PowerApps: Set a Field Value

This is one of those topics that I get asked about all the time, but is a little interesting to explain, because it works totally differently than what you may be used to in InfoPath or SharePoint Designer.  How do you automatically set a field’s value in PowerApps?  An example of a common scenario is when saving/submitting a form, is to set a status field to some certain value, maybe based on a condition in the form.  In this first, simple example, I’ll set a field called “Status” to say “Submitted” when I fill out a new form.

Here are the steps, at least one way to go about it:

For a customized SharePoint list form:

  1. Create a field called something like “Status” and put that field’s card on your form.
  2. Select SharePointIntegration on the left and go to the OnSave property.  Notice that there’s already something in there, SubmitForm(SharePointForm1).  You’ll be adding a new function in front of this one, with your logic.  In this example, only if it’s a new form, I want to set the status to Submitted when I first save it.  So, here’s my logic:
    If the mode of the form is New, then set a variable called varStatus to the value of “Submitted”.  Then submit the form to SharePoint.
    PowerApps-SharePoint-OnSave-condition
  3. Next step is to put the value of that variable in the status field.  Select the Status card, and go to the Default property of it.  If the variable varStatus is blank, then just show the value that’s already in that field.  Otherwise, if the variable is not blank then put the value of the variable in there instead.
    powerapps-sharepoint-status-card-submitted
  4. For a bonus, if you’d like to set the status so that no one can edit it in the form, select the Status card, and go to the DisplayMode property of it.  Set it to DisplayMode.View

For a PowerApps App (not a customized list form):

Step 2 is the only different step.  Select your Submit button if you already have it on your form (insert one if you don’t have one yet).  Go to the OnSelect property of this button.  Use the same formula shown in step 2 above.  Then proceed to step 3.

 

To set a field value based on another field’s value

If you’d like to have the status of your form, based on a certain condition, the example above just looks at whether the form is new or not, but if you want it to be based on the value of another field, your step 2 would be different.  In this example, if someone selects the word “Approved” in a choice field called “Manager Approval”, then you want to make the form’s status automatically say “Approved”.

  1. In the form, select the drop-down box inside the card for manager approval.  In this example, you can see that I went ahead and renamed mine and called it drpManagerApproval.  Rename yours to something useful here.
    powerapps-manager-approval-dropdown
  2. Then, go to the OnSave property of the form like you did in step 2 for a customized SharePoint list form, or if it’s not a customized list form, just go to your submit button. Basically, using that same logic, with having the varStatus, you need to know the name of the control that the value is in, then set the variable.  You also need to make sure to do step 3 above, exactly the same.
    image

There, as long as you understand the concepts of variables, controls and submitting, that’s all there is to it.

Looking for a more in-depth knowledge of PowerApps?  Check out my PowerApps Training classes!

2 comments

  • The approach you described does not always work. The PowerApps documentation states that formulas are not always guaranteed to execute in the order they are placed in the formula box. Also I have tried your approach with mixed results. Sometimes the Default property does not evaluate the variable you set before the SubmitForm formula runs and the new Status is not committed to the data source.
    I have had to make the updating of the Status and the submission of the form two discreet actions. First a checkbox or something similar is used to set the variable which in turn updates the value of the Status field then a button is used to submit the form. This guarantees the Status Default property has time to evaluate the variable before the form is submitted.

    Like

  • Hi Laura,

    I am watching your lot’s of video in PowerApps. It’s really help me a lot to learn and developing any application in PowerApps.

    Currently, i have a requirement where i get your advice.

    I have a Choice field in List and that is a Status field. I would like to Change the DisplayMode when the Status is “End” while Editing the item from List.

    That’s means in any Item of the List, if the Item Status is “End”, then any user not able to Edit the Item.
    Means, The SharePoint Form is in View mode (i.e. SharePointForm1. DisplayMode = DisplayMode.View). I am using PowerApps customize form.

    Below are the Steps to follow to create the scenario :

    Steps:
    Step 1 : Create a List (Name Tasks).
    Step 2 : Create a Status Field (Conatin values : “New” , “Inprogress”, “Failed”, “End”)
    Step 3 : Now Open the Tasks List. and Click PowerApps -> Customize forms.
    Step 4 : Add a Button. Button1.OnSelect = SubmitForm(SharePointForm1). Button1.Title : Submit
    Step 5 : Publish To SharePoint
    Step 6 : Create New Item with a Status “End”
    Step 7 : Save the Item using the Button ( Submit) and Close the apps.
    Step 8 : Now select the Item from the List and Click Edit
    Step 9 : The form opening with Edit Mode. But I need the Form will open in View mode. Because, the Item Status is “End”. User not able to Update any Field of the Item.

    I am looking for your advice.

    Thank you & Regards,
    Suman

    Like

Leave a reply or question

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.