cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
max81
Kudo Kingpin
Kudo Kingpin

Patch SharePoint List then get last ID doesn't works correct

Hi,

 

I'm using Patch to update a SharePoint List.

After saving the list, I want to call a flow with the just created List ID as parameter.

Unfortunately I don't get the new created ID: I get the ID the second last ID.

 

So my code is:

Patch(
    TestList,
    Defaults(TestList),
    Form1.Updates
);

Set(varID,Last(TestList).ID);

 

I also already tried to set a "Refresh(TestList)" in between, but it didn't solved the problem.
If I use the same function in really small Apps, it works fine. So maybe it depends on the size of the SharePoint List?

My last option would be to use UpdateForm/LastSubmit, but that would force me to "redesign" many steps.

1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @max81 ,

 

 

I think this should work for you. It can not only complete the patch function but also save the ID of the current patched record in the variable

 

Set(varID, Patch(TestList,Defaults(TestList),Form1.Updates).ID)

 

Sik

View solution in original post

7 REPLIES 7
WarrenBelz
Super User
Super User

Hi @max81 ,

Have you tried

Patch(
    TestList,
    Defaults(TestList),
    Form1.Updates
);
Refresh(TestList);
Set(varID,Last(TestList).ID);

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz : yes, I tried. But without success.

 

I also tried:

Patch(
    TestList,
    Defaults(TestList),
    Form1.Updates
);
Refresh(TestList);
Set(varID,Last(TestList).ID);
Refresh(TestList);
Set(varID,Last(TestList).ID);

 

Also without success. 

My workaround: first make an Submit with just the required field, than use LastSubmit to get the ID then Patch the missing fields.
But I still hope that there is a solution...

Try
Patch(
TestList,
Defaults(TestList),
Form1.Updates
);
Refresh (TestList);
ClearCollect(MyTest,TestList);
Set(varID,Last(MyTest).ID)

Hi @max81 ,

The reason I did not mention LastSubmit was that you were using a Patch instead of SubmitForm, which triggers that value.

Going back to your original post, you mentioned calling a Flow. You can return as (generally), the last item a value to Power Apps which can be the ID of what you have posted, however the posting would have to be from the Flow, not the Patch. This also uses a Flow quota which from what I see would be unnecessary simply to write data to a list.

You could also consider a (hidden) timer after the refresh for (say) five seconds before you do the Collect.,

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

v-siky-msft
Community Support
Community Support

Hi @max81 ,

 

 

I think this should work for you. It can not only complete the patch function but also save the ID of the current patched record in the variable

 

Set(varID, Patch(TestList,Defaults(TestList),Form1.Updates).ID)

 

Sik

@v-siky-msft perfect. I didn't know that.

 

@WarrenBelz thanks also for your help.

Thank you so much, this helped me a lot !!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,399)