cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ErikH63
Resolver I
Resolver I

Pre defining a variable defined by a flow return.

Hello,

I was wondering if anyone knew how to assign a variable defined in a flow return when the form is opened? 

 

In my case I call a flow on Submit: Set(NewIDText,BoardIDGeneration3.Run(Assigned_Number_Value.Value,User_ID_Value.Text,OverRideButton.Value)).

 

In another field (Board ID) in the PowerApp canvas form I display the variable returned from the flow:

Default = If(SharePointForm1.DisplayMode=Edit,NewIDText.newidtxt,Parent.Default)

 

My problem is that when someone is editing a list entry they see the previous NewIDText.newidtxt in the Board ID cell as opposed to the Parent.Default which I would like them to see. The easiest way I could think of solving this (without a complex if statement) would be to set NewIDText.newidtxt to Parent.Default when the form is visible, but I am not sure how to set a variable like NewIDText.newidtxt. It would then be overridden when the flow runs and shows the updated value.  Any ideas?   

 

Thanks,

  -Erik

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @ErikH63 ,

 

I assume that you have a gallery with many items. When you click on an item in the gallery, edit the form.

 

You could try this:

Create another variable. 

When you click on a record/item in the gallery, set this variable to 1.

For example:

Set onselect property of the gallery to:

Set(Variable,1);Reset(the Board ID control)

 

Set the Board ID control's Default property to:

If(Variable=1,ThisItem.your field value in your datasource,Variable=0,NewIDText)

 

Set the submit control's Onselect property to:

Set(NewIDText,BoardIDGeneration3.Run(Assigned_Number_Value.Value,User_ID_Value.Text,OverRideButton.Value).newidtxt);Set(Variable,0);Reset(the Board ID control)

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

 

View solution in original post

6 REPLIES 6
v-xiaochen-msft
Community Support
Community Support

Hi @ErikH63 ,

 

Could you tell me:

When do you want to display the value returned by flow and when to display parent.default?

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

Hi @v-xiaochen-msft, I need the parent.default when the user first edits a list item, I need to switch to the flow result when they hit submit.

 

Thanks,

     -Erik

v-xiaochen-msft
Community Support
Community Support

Hi @ErikH63 ,

 

There is a logical problem in it.

If the user edits the record and presses the submit button to trigger the flow, then he edits the item again, do you want the control to display "parent.default" or return value of flow?

 

If the user presses the button and closes the app and reopens it, which value do you want the control to display?

 

Best Regards,

Wearsky

Hello Wearsky, 

 

This is a little confusing, sorry.  The list contains the name of a board and its assigned ID number. If the ID number needs to be changed for this board the user edits the record, so when the record opens up in the form it needs to display the current ID number from the list (ID_DEC Default= Parent.Default).  They then can change the number and submit. The flow checks the ID number and if it is acceptable it assigns this number and sends it back to the form as the variable NewIDText.newidtex so now ID_DEC Default = NewIDText.newidtex otherwise it will just write the Parent.Default back to the record as opposed to the New ID.   

So the question was can I just assign the variable NewIDText.newidtex to the Parent.Default at the beginning and then the flow can just overwrite this with the new ID.  

 

I hope this makes sense.  Currently, I do have a version working where a variable is set when it is submitted so that an if statement can switch between the two values. 

 

v-xiaochen-msft
Community Support
Community Support

Hi @ErikH63 ,

 

I assume that you have a gallery with many items. When you click on an item in the gallery, edit the form.

 

You could try this:

Create another variable. 

When you click on a record/item in the gallery, set this variable to 1.

For example:

Set onselect property of the gallery to:

Set(Variable,1);Reset(the Board ID control)

 

Set the Board ID control's Default property to:

If(Variable=1,ThisItem.your field value in your datasource,Variable=0,NewIDText)

 

Set the submit control's Onselect property to:

Set(NewIDText,BoardIDGeneration3.Run(Assigned_Number_Value.Value,User_ID_Value.Text,OverRideButton.Value).newidtxt);Set(Variable,0);Reset(the Board ID control)

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

 

View solution in original post

Thanks Wearsky, I learned a lot from your reply regarding the reset, however, in my design there is a race condition in the flow upon submission.  When the variable is set to 0 on submit it toggles the  Board ID control's Default 

If(Variable=1,ThisItem.your field value in your datasource,Variable=0,NewIDText)

to NewIDText which is what the flow grabs instead of the "ThisItem.your field value in your datasource" which is fine if the form is new mode, but if it is in edit mode it overwrites the current value with the undefined NewIDText. 

Sorry this is very confusing and contorted. Since this is only an issue if the record is being edited and the user is requesting a new ID number I used this condition to set the Board ID control's Default.   

 

One question how do you get the code to be in the tan enclosed box, that made it easy to read.

 

Thanks,

    -Erik

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (21,077)