Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

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

Like (2) ShareShare
ReportReport
Posted on 19 Sep 2024 16:34:49 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
    FLMike Profile Picture
    FLMike 27,286 on 24 Sep 2024 at 01:29:50
    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
    COFSLab 24 on 23 Sep 2024 at 14:25:11
    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
    FLMike Profile Picture
    FLMike 27,286 on 21 Sep 2024 at 01:09:11
    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
    COFSLab 24 on 20 Sep 2024 at 16:11:48
    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
    Hussein Wahba 55 on 19 Sep 2024 at 22:38:21
    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
    Hussein Wahba 55 on 19 Sep 2024 at 21:03:42
    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
    COFSLab 24 on 19 Sep 2024 at 19:45:02
    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

End of Year Newsletter…

End of Year Community Newsletter…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #11 New Opportunities…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,654

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,440

Leaderboard
Loading complete