Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Please help! Patched collection to SP list not in correct item order

(2) ShareShare
ReportReport
Posted on by 24
Hello all, I've been trying to patch a collection to my SP list to make multiple new records. However, I keep bumping into the issue where the ID of the patch content is randomly shuffled despite the order of the items in the collection. 
 
Here's my patching code:
ClearCollect(
    BulkSRSubmission,
    ForAll(
        Gallery3.AllItems,
        {
            Title: JobNumberInput.Text,
            ControlNumber: ControlNumberInput.Text,
            SampleID: SampleIDInput.Text,
            DateCollected: DateCollectedInput.Text,
            TimeCollected: TimeCollectedInput.Text,
            DateReceived: DateReceivedInput.SelectedDate,
            TimeReceived: TimeReceivedInput.Text,
            RequestedAnalysis: RAInput.Text,
            SampleType: SampleTypeInput.Text,
            Preservative: PreservativeInput.Text,
            RelinquishedBy: RelinquishedByInput.Text,
            ReceivedBy: ReceivedByInput.Text,
            AcceptReject: AcceptRejectInput2.SelectedText.Value,
            DestroyDate: DestroyDateInput.SelectedDate
        }
    )
);

Patch(SampleReceiving2024,BulkSRSubmission)
How my collection looks like:
And the shuffled patched items in SP list:
 
Please help! Thank you!
  • Verified answer
    Michael E. Gernaey Profile Picture
    41,385 Super User 2025 Season 1 on at
    Please help! Patched collection to SP list not in correct item order
    The only way to patch in the order that you want would be to loop and patch 1 at a time, do not batch them.
     
    But I guess I would ask is there no data related to the "content" that would allow you to sort it so no matter what ID in SharePoint it received you could put it in order?
     
    Just asking, but yes the answer is doing a loop and patching them literally 1 by 1
  • COFSLab Profile Picture
    24 on at
    Please help! Patched collection to SP list not in correct item order
    Interesting, I was not aware of any of that. So with how the system works, is it impossible to patch the collection with the item order that I want?
  • Verified answer
    Michael E. Gernaey Profile Picture
    41,385 Super User 2025 Season 1 on at
    Please help! Patched collection to SP list not in correct item order
    Hi
     
    This is the answer, what you did with the For All simply avoided it
     
    The actual answer is because the system is Multi-threaded. When you push in a Batch, it breaks them off into separate threads (yes I know this for a fact having worked on it myself).
     
    So that's why it looks shuffled.
     
    How you submit them in batches means nothing as they aren't processed in "order" as that would be a waste to Batch updates to serialize them.
     
    thats the answer
     
    Your workaround is not so much a work around, as its how its intended.
     
     
  • COFSLab Profile Picture
    24 on at
    Please help! Patched collection to SP list not in correct item order
    That's what I thought too. Not entirely sure why patching a collection to SP list would have the content shuffled on my end. I did try something similar to what you suggested but it didn't work. Thank you regardless.
  • Hussein Wahba Profile Picture
    55 on at
    Please help! Patched collection to SP list not in correct item order
    Sounds weird for me, because as per Microsoft documentation both functions iterates on the list from the beginning to the end.
    Anyways, I'm happy you got that addressed.
  • Suggested answer
    Hussein Wahba Profile Picture
    55 on at
    Please help! Patched collection to SP list not in correct item order
    Could you try sorting the collection before posting it with batch

    ClearCollect(
        SortedBulkSRSubmission,
        Sort(
            BulkSRSubmission,
            SampleID, // or any other field you want to sort by
            Ascending
        )
    );
    Patch(SampleReceiving2024, SortedBulkSRSubmission);

  • Verified answer
    COFSLab Profile Picture
    24 on at
    Please help! Patched collection to SP list not in correct item order
    I found out the solution. Not sure why the behavior is like this, but I had to patch my SP list within Forall directly and not using any collection.
     
    ForAll(
            Gallery3.AllItems,
            Patch(SampleReceiving2024,
            {
                Title: JobNumberInput.Text,
                ControlNumber: ControlNumberInput.Text,
                SampleID: SampleIDInput.Text,
                DateCollected: DateCollectedInput.Text,
                TimeCollected: TimeCollectedInput.Text,
                DateReceived: DateReceivedInput.SelectedDate,
                TimeReceived: TimeReceivedInput.Text,
                RequestedAnalysis: RAInput.Text,
                SampleType: SampleTypeInput.Text,
                Preservative: PreservativeInput.Text,
                RelinquishedBy: RelinquishedByInput.Text,
                ReceivedBy: ReceivedByInput.Text,
                AcceptReject: AcceptRejectInput2.SelectedText.Value,
                DestroyDate: DestroyDateInput.SelectedDate
            }
        )
    );
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard