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

View solution in original post

@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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,484)