cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
CUCOOPE
Helper I
Helper I

Generating a unique ID and patch it to sharepoint list with filtering and without using "ID" of the list

Hi. I was trying to build a multi-user app and we need to generate a unique number to a sharepoint list according to different values seleted in a dropdown box. Here is an example:

 

Sharepoint List(Let's name it "SPList"):

PrefixPrefixIDUniqueIDRecordID
A111
B212
A123
A134
B225
C316

 

And the "Prefix" is seleted from a dropdown box(DB_001), "searchID" corresponses to "RecordID".

I had a button with code:

Patch('SPList',First(Filter('SPList', RecordID=searchID)),{

UniqueID: Text(If(Status="New",Last(Sort(Filter('SPList,PrefixID=DB_001.SelectedText.NumberID),UniqueID, Ascending)).UniqueID+1),"000000")
});

(A new record with a new recordID has been created before pressing the button)

When I was running the app alone it worked fine. But when multiple users press the button at about the same time, a network error occours saying that there is a change in record resulting a conflit, and duplicated UniqueID was generated.

 

Has anyone deal with this issue before? How can I achieve the expected result? Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

@CUCOOPE 

 

No, I am saying in my general idea that the button should not be pressed twice in the solution idea I gave specifically, because the Patch will be retried by the timer automatically. However, the gist of it is, the data has become stale, so if you must generate the ID's the way you are doing, an error is not really avoidable in this scenario where multiple users pressed the button at the same time. To avoid the error, you must let SharePoint generate the ID's on server side, such as how the ID's are already automatically generated when records are created in SharePoint. I presume you don't want to do that and must use your method - if so, you can't avoid an error in your scenario.

 

The general idea is that the Patch has to be run again because the data is stale, and the error cannot be avoided.

 

I have a simpler solution for you. Instruct the users that there is no way to avoid this error, and they should press the button again if they see the error.

 

If you want the users not to see this error at all, my solution gave an approach about how you can accomplish the goal and for the user not to see any error with that IfError and Timer kind of way.

 

View solution in original post

3 REPLIES 3

@CUCOOPE 

 

You can turn on formula-level error management,

 

poweractivate_0-1664838760107.png

 

 

 

and then use IfError to catch this situation.

 

 

 

When the button is pressed, you do not allow the button to be pressed again - so perhaps for example navigate to another screen right away - and on this screen you have a Label that says Please Wait, and a Timer Control  with duration of 3000 (3 seconds) that has AutoStart to true and Repeat true as well. Use IfError to swallow the error, and the timer will just rerun the patch again after 3 seconds - this patch will be rerun with the new records. If there is not an error, it should Navigate away from this Timer / please wait screen, perhaps back to the screen you were on. 

IfError(Patch(...),false,Navigate(InitialScreen))

 

 

 

See if the above helps as general starting point  to solve it @CUCOOPE 

 

 

Hmmm but the error doesn't occour because the same button was pressed twice. It was because multiple users are using the app, when user A press the button then user B press the button just a few seconds later, the record is changed while User B is still processing the Sort() etc. functions, resulting a conflict. Perhaps the solution is to reduce the time needed to calculate the UniqueID since it took around 10000 milliseconds for it to process the number and if another user press the same button (with a different log in), it will result in a conflict.

@CUCOOPE 

 

No, I am saying in my general idea that the button should not be pressed twice in the solution idea I gave specifically, because the Patch will be retried by the timer automatically. However, the gist of it is, the data has become stale, so if you must generate the ID's the way you are doing, an error is not really avoidable in this scenario where multiple users pressed the button at the same time. To avoid the error, you must let SharePoint generate the ID's on server side, such as how the ID's are already automatically generated when records are created in SharePoint. I presume you don't want to do that and must use your method - if so, you can't avoid an error in your scenario.

 

The general idea is that the Patch has to be run again because the data is stale, and the error cannot be avoided.

 

I have a simpler solution for you. Instruct the users that there is no way to avoid this error, and they should press the button again if they see the error.

 

If you want the users not to see this error at all, my solution gave an approach about how you can accomplish the goal and for the user not to see any error with that IfError and Timer kind of way.

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,618)