cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Eswald
Level: Power Up

Update index value on submit

Hi all,

 

I have the following case I cannot seem to get to work.

 

We created a form for a client that adds an item to a SharePoint list. In order to track the total number of submitted items in a year, an index number is generated by counting the number of items in a specific year and doing +1:

 

Text(CountRows(Filter('SPDataSource';StartsWith(ProjectNumber;Text(Now(); "[$-nl-NL]yyyy"))))+1)

This index number is then used to create a project number:

Concatenate(Text(Now(); "[$-nl-NL]yyyymmdd");"-XYZ-";Text(DataCardValue41_1)

These actions are performed by setting the default value of the corresponding data cards like this (I know I can test differently for a New Form, but we have different modes determined by a query string, so we put mode="New" for consistency):

If(mode="New";Text(CountRows(Filter('SPDataSource';StartsWith(ProjectNumber;Text(Now(); "[$-nl-NL]yyyy"))))+1);ThisItem.IndexNumber)

If(mode="New";Concatenate(Text(Now(); "[$-nl-NL]yyyymmdd");"-XYZ-";Text(DataCardValue41_1));ThisItem.ProjectNumber)

This all works fine, but since the forms are quite extensive, there is a possibility that there are 2 new forms opened at the same time by different users. As a result, the forms are saved with the same index numer and project number.

 

My solution was to update the index number when clicking the submit button, before actually submitting the form. However, this does not seem to work:

UpdateContext({indexNr:Text(CountRows(Filter('SPDataSource';StartsWith(ProjectNumber;Text(Now(); "[$-nl-NL]yyyy"))))+1)});;
UpdateContext({apprStatus:"Form submitted"});;
SubmitForm(CombinedForm)

The above code works (tested by manually lowering the index number), but only updates the number to the value it was before.
I thought that the state of the data source might have something to do with it, so I tried adding a refresh of the datasource before updating the index number, but that was to no avail. 

 

So any suggestions on how to solve this issue would be very much appreciated!

 

Kind regards,

 

Eswald

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Update index value on submit

Hi @Eswald,

 

Could you please share a screenshot abour your app's configuration?

Could you please share more details about your SP list? Do you create a IndexNumber column within your SP list?

Further, does the "DataCardValue41_1" represent the IndexNumber Data card value?

 

If you want to refresh/update the IndexNumber value before you submit the form, I afraid that there is no way to achieve your needs in PowerApps currently.

 

In addition, I think it is not necessary to create a IndexNumber column to store the total number of submitted items in a year. You could get the current total number of submitted items in a year with the following formula (that you mentioned):

CountRows(Filter('SPDataSource';StartsWith(ProjectNumber;Text(Now(); "[$-nl-NL]yyyy"))))

 

As an alternative solution, I think the Patch function could achieve your needs (instead of the SubmitForm() function). I have made a test, please take a try with the following workaround:

 

Set the OnSelect property of the "Submit" button to following formula:

 

If(
  EditForm1.Mode=FormMode.New,
  Patch(
      'SPDataSource',
      Defaults('SPDataSource'),
      {
        Title:DataCardValue1.Text,
        ...
        IndexNumber:CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1,
        ProjectNumber:Concatenate(Text(Now(),"[$-nl-NL]yyyymmdd"),"-XYZ-",Text(CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1)),
        ...
      }
   )
)

 

On your side, you may need to type the following formula:

If(
  mode="New",
  Patch(
      'SPDataSource',
      Defaults('SPDataSource'),
      {
        Title:DataCardValue1.Text,
        ...
        IndexNumber:CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1,
        ProjectNumber:Concatenate(Text(Now(),"[$-nl-NL]yyyymmdd"),"-XYZ-",Text(CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1)),
        ...
      }
   )
)

Note: The Title, IndexNumber and ProjectNumber are all columns in your SP list.

 

 

More details about the Patch function in PowerApps, please check the following article:

Patch function

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Community Support Team
Community Support Team

Re: Update index value on submit

Hi @Eswald,

 

Could you please share a screenshot abour your app's configuration?

Could you please share more details about your SP list? Do you create a IndexNumber column within your SP list?

Further, does the "DataCardValue41_1" represent the IndexNumber Data card value?

 

If you want to refresh/update the IndexNumber value before you submit the form, I afraid that there is no way to achieve your needs in PowerApps currently.

 

In addition, I think it is not necessary to create a IndexNumber column to store the total number of submitted items in a year. You could get the current total number of submitted items in a year with the following formula (that you mentioned):

CountRows(Filter('SPDataSource';StartsWith(ProjectNumber;Text(Now(); "[$-nl-NL]yyyy"))))

 

As an alternative solution, I think the Patch function could achieve your needs (instead of the SubmitForm() function). I have made a test, please take a try with the following workaround:

 

Set the OnSelect property of the "Submit" button to following formula:

 

If(
  EditForm1.Mode=FormMode.New,
  Patch(
      'SPDataSource',
      Defaults('SPDataSource'),
      {
        Title:DataCardValue1.Text,
        ...
        IndexNumber:CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1,
        ProjectNumber:Concatenate(Text(Now(),"[$-nl-NL]yyyymmdd"),"-XYZ-",Text(CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1)),
        ...
      }
   )
)

 

On your side, you may need to type the following formula:

If(
  mode="New",
  Patch(
      'SPDataSource',
      Defaults('SPDataSource'),
      {
        Title:DataCardValue1.Text,
        ...
        IndexNumber:CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1,
        ProjectNumber:Concatenate(Text(Now(),"[$-nl-NL]yyyymmdd"),"-XYZ-",Text(CountRows(Filter('SPDataSource',StartsWith(ProjectNumber,Text(Now(),"[$-nl-NL]yyyy"))))+1)),
        ...
      }
   )
)

Note: The Title, IndexNumber and ProjectNumber are all columns in your SP list.

 

 

More details about the Patch function in PowerApps, please check the following article:

Patch function

 

 

Best regards,

Kris

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Eswald
Level: Power Up

Re: Update index value on submit

Hi @v-xida-msft,

 

Apologies for the extremely late reply, I haven't been able to implement your suggestions until now due to circumstances.

However, your suggestions helped a great deal. I will update this topic with a detailed explanation of how I implemented it when I've got more time.

 

Thank you for your help!

 

Cheers!

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, August 21st at 8am PDT

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

SixthImage

Power Summit Australia 2019

August 20-23rd 2019

Users Online
Currently online: 262 members 3,675 guests
Please welcome our newest community members: