cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PowerUser19
Helper II
Helper II

Incremental number based on submission

Hello experts,

 

I am collecting the form details for visitor requests. There are 2 options to submit request. Single submission and Multiple visitor request submission. For multiple submission, I am collecting the list of records in a collection and patching the multiple records in the SharePoint list. I use different submit buttons for each type of submission. Please refer the screen shots attached. 

 

I am already using Unique ID in SharePoint list for some references. My requirement is, I need to create Incremental Visit-ID. If the request is submitted as Single visitor request - the ID should be say "1". If the next request is a multiple request submission and say there are 4 records, when I patch the data in SharePoint I need the Visit ID for all 4 records to be say "2".  Basically need to group each request and have an incremental number. Any help is highly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
BCBuizer
Super User
Super User

Hi @PowerUser19 ,

 

This code was only meant to generate a new VisitID upon creation of a new item, not to update existing items. It should be included in the Patch statement you already have for the creation of new items.

 

Come to think of it, in the case of multiple new items this will not work as it will keep incrementing the VisitID after each item, even if they belong to the same visit request. 

 

What you'll have to do is save the value in a variable and then use that in your Patch:

 

UpdateContext(_VisitID: Last(Sort(SharePointList,'Unique ID')).'Unique ID' +1});
ForAll(
    //Items you want to save in your data source
    Patch(VisitorRequestList, Defaults(VisistorRequestList, 
       {
       //..... 
       'Visit ID' :  _VisitID
       }
    )
);

 



Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

View solution in original post

4 REPLIES 4
BCBuizer
Super User
Super User

Hi @PowerUser19 ,

 

I assume you have figured out how to patch the requests to your SharePoint list and are only looking for a method to assign a unique number.

 

For that, you can use the below example to populate the 'Unique ID' column (or whatever name you have):

 

{'Unique ID': Text(Value(Last(Sort(SharePointList,'Unique ID')).'Unique ID')+1)}

 

The Text and Value function are only included because I assume you are using a Text type column. If it is a number type, you have to leave them out:

{'Unique ID': Last(Sort(SharePointList,'Unique ID')).'Unique ID' +1}

 



Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.
PowerUser19
Helper II
Helper II

Hi @BCBuizer ,

Thanks for the response. I am still facing difficulty with creating the incremental number. 

Yes, I am able to patch other fields from the form. I need help with the incremental number. 

I tried the below code. The SharePoint VisitID is still empty after the below code is executed. VisitID is a number column in SharePoint list. I tried with and without "Text(Value" but no luck. I am sure missing something. 

Patch(VisitorRequestList,LookUp(VisitorRequestList,Title=DataCardValue46_2.Text),{'Visit ID':Text(Value(Last(Sort(VisitorRequestList,'Visit ID')).'Visit ID'))+1})

and 

Patch(VisitorRequestList,LookUp(VisitorRequestList,Title=DataCardValue46_2.Text),{'Visit ID':Last(Sort(VisitorRequestList,'Visit ID')).'Visit ID')+1})

 

If a single request is submitted, the database should have an incremental visit ID. 

If multiple requests are submitted at the same time, the visit ID should be same for all requests. 

Single Request: 

Bob - Visit ID - 1

 

Multiple Requests:

Jim - Visit ID - 2

Ken - Visit ID - 2

Joe - Visit ID -2

 

 

I cannot use the above code in case of multiple record submission. Because I cannot check the title = datacardvalue. I need the VisitID to be same for all the records submitted in the multiple request form.

BCBuizer
Super User
Super User

Hi @PowerUser19 ,

 

This code was only meant to generate a new VisitID upon creation of a new item, not to update existing items. It should be included in the Patch statement you already have for the creation of new items.

 

Come to think of it, in the case of multiple new items this will not work as it will keep incrementing the VisitID after each item, even if they belong to the same visit request. 

 

What you'll have to do is save the value in a variable and then use that in your Patch:

 

UpdateContext(_VisitID: Last(Sort(SharePointList,'Unique ID')).'Unique ID' +1});
ForAll(
    //Items you want to save in your data source
    Patch(VisitorRequestList, Defaults(VisistorRequestList, 
       {
       //..... 
       'Visit ID' :  _VisitID
       }
    )
);

 



Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.
PowerUser19
Helper II
Helper II

Hi @BCBuizer ,
Thanks a lot. Saving the value in a variable and incrementing it worked! 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,149)