cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Power Participant
Power Participant

Patching multiple items on saving edit form SharePoint

What I'm trying to achieve is when you edit an Item in the SharePoint form it will save the input as normal but it will also Patch items in another SharePoint list in a LookUp column.

 

List1: This list contains the form you can edit. The form contains a LookUp column named "Related Tickets" This is linked to the Column TicketID in List2. It also contains a single line of text column named "Problem ID".


List2: This list contains a LookUp column named "Problem ID"  and a Single line of text column named "TicketID"

 

When the user hits the save button after editing the form in List1, then I want it to not only save the data for the item but I also wish for it to Patch the all Item related to it with the "Problem ID", for example if I have added 4 items in the "Related Tickets" dropdown in the form from List1 and I hit the save button it will Patch the "Related Tickets" in List2 with the "Problem ID" from the edit form List1.

 

Now the following is working but I'm not sure it is the best or optimal way of doing it.
OnSelect on the save Button. (I have left out submit form) And sorry for the bad naming of the collections, just a test.

 

ForAll(
ClearCollect(RelatedTicketsCol5, varSelectedTicketProblem.'Related Tickets');
Collect(RelatedTicketsCol5, DataCardValue29_1.SelectedItems),

{
    Id: DataCardValue29_1.Selected.Id,
    Value: DataCardValue29_1.Selected.Value

});

//varSelectedTicketProblem is ThisItem
//I want to collect the current related tickets in the item and collect all the extra added.

 

 

 

ClearCollect(RelatedTicketsCol6, ForAll(Distinct(RelatedTicketsCol5, ThisRecord),ThisRecord.Result));

//I do the above to sort out duplicates in the collection RelatedTicketsCol5, for some reason i always recive one related ticket as a duplicate.

 

 

 

ClearCollect(
    TestCol,
    Concatenate(RelatedTicketsCol6.Value, ""));

//The above makes it possible for me to use LookUp as single line of text against the collection as the TicketID is a single line of text.

 

 

 

ForAll(
    TestCol,
    Patch(
        List2,
        LookUp(List2, TicketID = Result),
        {
            'Problem ID':
            {
                Id: varSelectedTicketProblem.ID,
                Value: varSelectedTicketProblem.'Problem ID'
                }
        }
    ));

//The above patches all related tickets with the "Problem ID" from List1

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

You could try simplifying it by adding a formula to the OnSuccess property of the SharePoint Form. This way it only updates when the form is successfully saved. It would look something like this and this would be all you would need. 

 

Set(varLastSubmit, SharePointForm1.LastSubmit);
ForAll(
    varLastSubmit.'Related Tickets' As _SelectedLookupItems,
    Patch(
        List2,
        LookUp(List2, ID = _SelectedLookupItems.Id),
        {
            'Problem ID':
            {
                Id: varLastSubmit.ID,
                Value: varLastSubmit.'Problem ID'
                }
        }
    )
)

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

5 REPLIES 5
Super User
Super User

You could try simplifying it by adding a formula to the OnSuccess property of the SharePoint Form. This way it only updates when the form is successfully saved. It would look something like this and this would be all you would need. 

 

Set(varLastSubmit, SharePointForm1.LastSubmit);
ForAll(
    varLastSubmit.'Related Tickets' As _SelectedLookupItems,
    Patch(
        List2,
        LookUp(List2, ID = _SelectedLookupItems.Id),
        {
            'Problem ID':
            {
                Id: varLastSubmit.ID,
                Value: varLastSubmit.'Problem ID'
                }
        }
    )
)

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

@Jeff_Thorpe Thank you for responding i will try this.
Need to read up on Lastsubmit.

Where you type: As _SelectedLookupItems, could you care to explain this for me is _SelectedLookupItems something i need to have like a variable or what should i input there, as i do not want to get a deletagation warning.

@Jeff_Thorpe Thank you it is working perfect, could you point me in the direction where i can read up opn how to use As _SelectedLookupItems, and this also does not affect delegation correct?

 

 

Super User
Super User

@JimmyWork , The "As" is giving the ForAll() record a name, so that it is easier to work with in the formula. Here is the link to the documentation on "As".

 

ThisItem, ThisRecord, and As operators 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

@Jeff_Thorpe Last question 🙂

How would i get the ID for a new Item, so if i have a form to create a new item i cannot use LastSubmit, but how do i get the current ID for the Item i just created.

Never mind i used ResetForm in the wrong place, everything works, big thank you again and i learned something 🙂

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (12,492)