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

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 III
Helper III

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 III
Helper III

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

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 (4,543)