Site icon @WonderLaura

Power Apps: 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. This syntax is assuming that your status field is a text field.  If it were a choice or lookup or anything else, the syntax would be different for different types of fields.
  3. Next step is to put the value of that variable in the status field.  Select the Status card, unlock it, 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.
  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.
  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.

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!


Exit mobile version