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!

15 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

  • Hi Laura,

    I was wondering how I would set a metadata field in an item in one list based on the value of the same metadata field in a related item in another list. The two lists are related through a lookup column (not the metadata one) and I don’t want to force users to pick the same metadata value manually, but it should be the same for both.

    Thanks,
    Dave

    Like

  • Actually, I think I just figured it out. It would have been difficult at best if I had to know the value of each, but since I already had the column set (manually) in one item, I was just able to use the references to the Path, WssId, TermGuid, Value and Label. Worked like a charm!

    Like

  • I am using powerapps to customize list forms. How can I move these to prod. Tenent.

    MS says we cannot… it’s not available feature now.

    So, what should be idle way of development if we can’t move these customised powerapps list form.

    Like

    • You should use standalone apps if you need to be able to move an app or make a copy of it in any way. Unfortunately that’s something you should decide before you start creating an app or customizing a list form with PowerApps.

      Like

    • With stand-alone apps, though, when you click on the New or Edit buttons/links in the SharePoint list, the PowerApps form will not come up, right? Plus, you have to kind of build everything from scratch.

      Like

    • Yes. There are definitely pros and cons to both ways of creating apps, unfortunately. It’s something you have to weigh and decide each time you create an app. Maybe you could build it as a standalone app, and then do a customized list form app that immediately redirects you to the standalone app for that list.

      Like

    • Oh, I think I understand what you were talking about now. A classic form that redirects to the PowerApps app. I’ve done classic view forms that redirect to edit forms, in order to bypass that step, so same methodology, I guess. Thanks!

      Like

    • A PowerApp can launch another PowerApp, using the Launch function.

      Like

    • Oh, OK, even better! Thanks!

      Like

  • We have a PowerApps form with several fields that must be completed before the form can be submitted to the Sharepoint List.

    We can’t make them required or mandatory on the Content-Type and List because we want the users to be able tosave their data, and come back to it to edit it before Submitting…

    So we need to disable/hide the Submit button until these fields are completed by the user.

    In our Submit Button control we are using a formula to control the Visibility property of the button, or it’s container which is the footer.

    So we have tried this kind of thing:

    If(
    And(
    TitleField.Text “”,DescOfInitiativeField.Text “”, DateRaisedField.SelectedDate Date(
    1900,
    01,
    01
    ),
    Not IsEmpty(PersonalDataChoiceField.SelectedItems.Value),
    Not IsEmpty(SpecialCatChoiceField.SelectedItems.Value),
    Not IsEmpty(ChildrensDataChoiceField.SelectedItems.Value),
    Not IsEmpty(CriminalChoiceDataField),
    Not IsEmpty(SourcesOfDataChoiceField.SelectedItems.Value),

    but we are not having any luck…

    So what’s the correct way to go about this? How can we test that at least one of the options in each of our combo-box fields is selected?

    Like

    • I recommend selecting each card, and put logic in the “required” property for each card. That way, you don’t have to make them required in SharePoint, but they are required just in PowerApps. So something like if status equals draft, then required is false, otherwise true.

      Like

  • Hi Laura, how would I go about using this logic to change the value of one drop down menu (DD1), based on the selection of a second drop down menu (DD2)? When I try to do this, I get an error message: “The property expects Record Values, but this rule produces incompatible text values”

    Like

  • Hi Laura,

    I am playing around with the PowerApps Leave Request template.

    On that template has the submit to for approval users. Is it possible to used this using static value from a button instead of using change popup?

    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 )

Connecting to %s

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