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

Retrieve the SharePoint list ID and generale a code in Power Apps

Hello,

 

I want to generate a code after i submit the form in Power Apps but i cannot retrieve the SP list ID.

By default the Code field is : "En cours de création", when i fill the form and i click on the button and OnSelectUpdateContext({CodeGenerate: Concatenate("3F-"; Label4.Text; "2020-";DataCardValue6.Text; "-00"; Label4_1.Text)}) ; submitForm(Form1)

And on Properties Code field : Coalesce(CodeGenerate; "En cours de création")

 

Quetsion 1 : He save the form in SharePoint but the ID is empty, how can i update the code with the ID ?

 

Question 2 : How can i put the year dynamically instead a static number "2020" ?

See images below.

 

Any ideas ?

Thanks

 

3.PNG

 

33.PNG

 

333.PNG

 

3333.PNGafter the 00 should be the ID number.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Kingsman 

Yep, that's what I meant by this:

NOTE: you SHOULD replace the Label14.Text and DataCardValue6.Text with Form1.LastSubmit.whateverField 

Replace whateverField with the names of the fields that those controls derive from.

In general it is never good to refer to the controls in the EditForm directly.

 

So, whatever field is defined for the DataCard that holds DataCardValue39 in it, as well as the DataCard field for DataCardValue6, you should use that. So, for example, if the column/field in your EditForm for the DataCard with DataCardValue39 is PrimeCode and the one for DataCardValue6 is SubCode

Then your formula would be this:

UpdateIf(yourDataSource; ID=Form1.LastSubmit.ID;
    {AFECode: Form1.LastSubmit.PrimeCode  & "-" & Text(Year(Now())) & "-" & Form1.LastSubmit.SubCode &  "00" & Text(Form1.LastSubmit.ID; "00")
    }
)

Try to always refer to the LastSubmit values rather than the DataCards for two reasons: 

1) You might change your control type in a DataCard and then all your formulas that reference that control will now break.  If you reference the LastSubmit (and Updates as well prior to submit) then you will not have breaking formulas.

2) Your form might change modes (as you are forcing a NewForm in that formula) and there is no guarantee that the values in those controls is valid any longer.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@Kingsman 

You will not have an ID on a new item until it is submitted. 

You will have to patch your submitted record after you submit with the ID that was generated by SharePoint.

Change your formula to the following:

SubmitForm(Form1)

Now in the OnSuccess action of Form1, put the following:

UpdateIf(yourDataSource; ID=Form1.LastSubmit.ID;
    {CodeGenerate: "3F-" & Label4.Text & Text(Year(Now())) & "-" & DataCardValue6.Text & "-00" & Text(Form1.LastSubmit.ID; "00")
    }
)

NOTE: you SHOULD replace the Label14.Text and DataCardValue6.Text with Form1.LastSubmit.whateverField 

Replace whateverField with the names of the fields that those controls derive from.

In general it is never good to refer to the controls in the EditForm directly.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hello @RandyHayes ,

 

I tried to do the same and it's working except without the text value. (See below)

Means he should take the text value from DataCardValue39 (ex: 3F-DGE) & the year (2020) & the text value from DataCardValue6 (ex: 0348) & the 00 + ID so it should like this : 3F-DGE-2020-0348-00ID

 

Thank you in advance,

 

 

A.PNG

 

AA.PNG

 

 

 

 

RandyHayes
Super User
Super User

@Kingsman 

Yep, that's what I meant by this:

NOTE: you SHOULD replace the Label14.Text and DataCardValue6.Text with Form1.LastSubmit.whateverField 

Replace whateverField with the names of the fields that those controls derive from.

In general it is never good to refer to the controls in the EditForm directly.

 

So, whatever field is defined for the DataCard that holds DataCardValue39 in it, as well as the DataCard field for DataCardValue6, you should use that. So, for example, if the column/field in your EditForm for the DataCard with DataCardValue39 is PrimeCode and the one for DataCardValue6 is SubCode

Then your formula would be this:

UpdateIf(yourDataSource; ID=Form1.LastSubmit.ID;
    {AFECode: Form1.LastSubmit.PrimeCode  & "-" & Text(Year(Now())) & "-" & Form1.LastSubmit.SubCode &  "00" & Text(Form1.LastSubmit.ID; "00")
    }
)

Try to always refer to the LastSubmit values rather than the DataCards for two reasons: 

1) You might change your control type in a DataCard and then all your formulas that reference that control will now break.  If you reference the LastSubmit (and Updates as well prior to submit) then you will not have breaking formulas.

2) Your form might change modes (as you are forcing a NewForm in that formula) and there is no guarantee that the values in those controls is valid any longer.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Kingsman
Helper II
Helper II

Thank you @RandyHayes 

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,044)