cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JGootee
Level: Powered On

How to set default field between two alternating values on form submit?

When a new form is submitted I need text field QAReviewGroup to be set to QA Review 1.

Then when next new form is submitted I need text field QAReviewGroup to be set to QA Review 2.

With this value alternating on every new form submission.

 

I tried using LastSubmit property on the (hidden) Data Card on the form, both for the Card default and the field default value, and on the Screen OnVisible property.  Probably I have the expression wrong?

 

ToggleFormFieldDefaultValueHow.png

 

And I am guessing that expression should only be used in one of those three places?

 

I also tried creating an UpdateContext variable on the Screen OnVisible property for the new form screen, and setting the QAReviewGroup default value to that variable, but couldn't figure out how to 'toggle' the setting of the variable.

 

I appreciate any ideas on how to do this - thank you! 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
PauwelsSven
Level 8

Re: How to set default field between two alternating values on form submit?

Hi, 

 

Try 'CSS Request Form Copyin stead of CSS Request Form Copy.

Set this to DataCardValue26:

image.png

Regards.

tchin-nin
Level 10

Re: How to set default field between two alternating values on form submit?

You don't see any delegation warning because they appear only on undelegable operator or type within a delegable function. Last or First are not delegable functions. 

You're right I'm always confused, you should use a Descending sort Order.

 

On your SubmitButton, your first action should be 

Refresh('CSS Request Form Copy');

 

It will make PowerApps aware of the last added records yo have the very last value.

 

Theo

13 REPLIES 13
tchin-nin
Level 10

Re: How to set default field between two alternating values on form submit?

Hi @JGootee

 

The LastSubmit property of a form is used to retrieve the last item submitted through this form on the current use of the App, meaning if you close and reopen the app you won't be able to retreive anything with this property.

 

What you need to do is, at the submission, retreive the last item of your datasource. I suggest you to do so on the submission not on start (or on visible) because people can have added new item between the time the user has opened the app and the time he submits the form.

 

DataCardValue26.Text :
varQAReviewGroup

SubmitButton.OnSelect : 
UpdateContext({varQAReviewGroup:If(First(Sort('SpeXtra Project List',ID,SortOrder.Ascending)).QAReviewGroup = "QA Review 1","QA Review 2","QA Review 1")});
SubmitForm(frmNewSpeXtraProject)

Théo

JGootee
Level: Powered On

Re: How to set default field between two alternating values on form submit?

Hi @tchin-nin,

 

Thank you very much - I think you are close to solving this. Everything looks good to me, but the QAReviewGroup field value is not alternating on successive form submissions as we need.

 

Here is current Submit button OnSelect=UpdateContext({cvarQAReviewGroup:If(First(Sort('CSS Request Form Copy',ID,SortOrder.Ascending)).QAReviewGroup = "QA Review 1","QA Review 2","QA Review 1")});
SubmitForm(frmNewSpeXtraProject)

 

The result of that after many tests is QAReviewGroup field in the CSS Request Form Copy SP list is always set to "QA Review 2" on 4 tests.

 

I thought maybe we needed to switch the sort order to SortOrder.Descending, to compare to most recently submitted record, and I tested that update 4 times and value returned to QAReviewGroup field in the list was always "QA Review 1"

 

I think maybe I interpreted this part of your answer incorrectly?:

DataCardValue26.Text :
varQAReviewGroup

To achieve the instruction just above,, I changed Update property for the Card from DataCardValue26.Text to cvarQAReviewGroup.  Is this incorrect?   (I named the new context variable cvarQAReviewGroup, just fyi.)

 

QAReviewDataCardDefault.png

 

I also tried leaving the Update property for the Card set to DataCardValue26.Text, and changed the Default property for DataCardValue26, and got the same result as above.

 

Any ideas where I went wrong?

Thanks very much for your help on this!

Jim

PauwelsSven
Level 8

Re: How to set default field between two alternating values on form submit?

Hi,

 

OnVisible = Set(cvarQAReviewGroup, "Review Group " & (Last(Split(Last(CSS Request Form Copy).QAReviewGroup , " ").Result).Result)+1)

 

OnSubmit = Navigate(ThisPage, ScreenTransition.None)

 

DataCardValue26.Text = cvarQAReviewGroup

 

Does this work for you?

JGootee
Level: Powered On

Re: How to set default field between two alternating values on form submit?

Hello @PauwelsSven - thanks for your suggestion, but seems the Last() isn't formatted exactly right, so I can't set the global variable to test this solution:

SetQAReviewVarExpErrorMsg.png

 

I am still not sure why @tchin-nin solution didn't work.  It looks right to me.

 

Still need to confirm where to apply the expression you both provided:  

DataCardValue26.Text = cvarQAReviewGroup

 

Do you mean that I should replace Update=DataCardValue26.Text  with Update=cvarQAReviewGroup, for the crdQA ReviewGroup card?  Or should I be inserting that variable in the DataCardValue26 field within that card, somewhere?

 

QAReviewGroupDataCardQue.png

 

Thanks - still hoping we can figure this out.

PauwelsSven
Level 8

Re: How to set default field between two alternating values on form submit?

Hi,

Make sure your Source are ok, then it will work.

Replace Datacard26 textinput.text with the var.
JGootee
Level: Powered On

Re: How to set default field between two alternating values on form submit?

Hi @PauwelsSven

 

I am confused by your last response:

 

"Make sure your Source are ok, then it will work."

I am getting an error when inserting the expression you provided (see screenshot above for error msg), and am still getting an error for that expression.  How does the 'Source' fix that?

QARevExpressionErrorEx2.png

 

Then can you please send me an image to explain where the var is inserted, per this statement: 

 

"Replace Datacard26 textinput.text with the var."
Thanks for your help. 

 

PauwelsSven
Level 8

Re: How to set default field between two alternating values on form submit?

Hi, 

 

Try 'CSS Request Form Copyin stead of CSS Request Form Copy.

Set this to DataCardValue26:

image.png

Regards.

JGootee
Level: Powered On

Re: How to set default field between two alternating values on form submit?

:-)

@PauwelsSven

It works!  Thank you for your patience!!

I am sorry I should have gotten what you mean by fix 'source'...and if I had typed in your solution instead of cutting and pasting I would have caught that too.

 

I am not going to mess with success and am very grateful, but this is the first expression I can even figure out when looking at it and trying to parse how it works:  Set(cvarQAReviewGroup, "Review Group " & (Last(Split(Last('CSS Request Form Copy').QAReviewGroup , " ").Result).Result)+1)

 

But you solved it and I am very grateful!

 

Thank you,

 

 

PauwelsSven
Level 8

Re: How to set default field between two alternating values on form submit?

Hi @JGootee,

 

Little adjustment to the formula.

I didn't read the alternate stuff, sorry... but here is the solution I tested out myself.

 

If( Value(Last(Split(Last('CSS Request From Case'). QAReviewGroup , " ").Result).Result) = 2, Set(cvarQAReviewGroup, "Review Group " & ((Last(Split(Last( 'CSS Request From Case' ). QAReviewGroup , " ").Result).Result)-1)), Set(cvarQAReviewGroup, "Review Group " & ((Last(Split(Last( 'CSS Request From Case' ). QAReviewGroup , " ").Result).Result)+1)))

 

With this formula it alternates.

 

image.png

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

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

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 45 members 4,577 guests
Please welcome our newest community members: