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:
- Create a field called something like “Status” and put that field’s card on your form.
- 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.
- 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.
- 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”.
- 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.
- 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!
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.
To your point, here’s how I did it:
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 :
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,
Go to the SharePointIntegration property called EditForm. Put some logic in there. If status equals “end” then ViewForm(formname). See if that works.
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.
From within PowerApps, you can use the Patch function to write to another list. Make sure to add that list as another data connection.
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!
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.
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.
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.
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.
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!
A PowerApp can launch another PowerApp, using the Launch function.
Oh, OK, even better! Thanks!
This is possible now. See https://www.microland.com/insights/blogs/the-power-to-move-powerapps-customizations-between-tenants. I followed the steps and was able to migrate the form from the list on the dev site to the list on the production site.
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:
TitleField.Text “”,DescOfInitiativeField.Text “”, DateRaisedField.SelectedDate Date(
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?
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.
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”
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?
I have customized form in power apps and I have custom List Field Request status. How can update this field to submitted while submitting new form and update this field to Approved when approver edit it edit form. This field while not be available in form view it will be hidden in new and edit form but only available in close form.
Thanks, and Regards,
We have tried this approach it works great for Form in New Mode. but then once request is submitted Manger open form in edit mode Then should we use SubmitForm or EditForm menthod . On form load global variable should fetch current status and then it should clear global variable else it shows up last status of last entry on load.
Thanks and Regards,
Can we assign SharePoint List field value of particular item to global variable on load of PowerApps.
This check Request status and navigate screen of PowerApps
I’m also trying to do this, and would love to hear the answer. I’ve seen a couple pages with suggestions, but results seem to be unpredictable… sometimes the field pointing to the variable gets set correctly, and sometimes not, with no pattern that I can discern.
Is there any way to set the default value of a people picker to a specific user? I’ve found references for defaulting a people picker control to the current logged in user but that’s not what I’m after.
Hi, I’m trying to extract emails out of a repeating table in an InfoPath form so that I can send an email response form to each person identified. I’m new to Flow and having some trouble figuring out how to extract that data.
You can’t extract data out of repeating tables in InfoPath. One of the many reasons to stop using InfoPath.
Hi Laura, I am curious to know if you have ever had a delegation error on the form in PowerApps – showing up against the default formula for Item (SharePoint form)? It is objecting to First. I have read First is non-delegable but it seems odd that the error is for a default formula…thanks
Thanks for this article Laura! I had been setting Default of the control (text field) to a variable instead of setting Default for the card itself and wasn’t behaving as I expected. Followed your guidance and got it working. Thank you!
so what if I have a var set called newstatus. And I want the value of that to go into a field on my form. What I thought would work is in the default of the field on form I say If(not(isblank(newstatus)),newstatus, thisitem.status). So that if newstatus variable wasn’t set in the logic then the status field stays left alone but if something is in newtatus variable then the status gets changed. It looks to work, I can see it on form. Then I click save and it goes away and leaves the status unchanged. Ideas?
Not sure where exactly you’re putting that formula you mentioned, but you should put it in the “Update” property of the card for the status field.
When I try to use your conditional formula for the default value of my Status field, I keep getting the error message that it is expecting a Record value in place of my variable. I have declared my variable and populated it in the OnVisible of my form. What am I doing wrong?
How to clear a field’s value based on condition? I write the following formula to the “Reset” property of that “DataCardValue” but it works only on a new form. It does not work on an edit form. Can you please help?
Hi Laura, I really appreciate the support you provide; it’s an old post, still, perhaps you can help me out. I’m working with a customised list. Set(varStatusNum, 0) works, but for some reason, Default=varStatusNum isn’t written into the SPO-List. I’ve tried both OnSave on both SharePointIntegration and a button, but no luck. Do you have any ideas as why this might be the case? Thx, Christian
Hi, are you patching it to the list after submitting a form?
How do I set multiple field values? I was able to do it for my Status column but I have others.
You can update multiple fields in your patch function.
How to I set the Title field with the value from a People Picker field in PowerApps?
Hello Laura, I see this post is old, how ever, hope you can help me on this.
What should I do if i wanted to the value “a” make the value “b” field automatically depending on the select choice of value “a”.
If you can help me here or you had extra links/ information I´ll be really greatfull
Hi Laura, If I select item type as “A”, then my status fields should display only 5 values out of 10. Is this possible?
I have a question. I have a status field in my PowerApp that can have a few different values, which are being set by a PowerAutomate flow. Typically, once this field is set to “Finance approved”, a purchaser will go back into this app and upload a receipt, which gets attached to this row in Sharepoint. Once they do this, I’d like PowerApps to set the value of the status field to “Receipts attached”. This way my PowerAutomate flow can go ahead and let my Finance person know that the purchaser has bought the item and attached a receipt. I want to automate this step because my users keep forgetting to do this.
Hi Richard, you can do this from Power Apps using the Patch() command. I teach all of the details of how this can be done with demos, examples and labs in my course: https://www.iwmentor.com/courses/powerapps-training
I have question. I have custom list form, that if someone attempts to Save the form with the following criteria, please disallow the Save operation with the following message “Please enter new employee’s Email Address before Completing this form.”
Person attempts to Save the form AND
Task Status = Completed AND
Email Address is Blank
Please advise me on how to input the validation to the form.
Here’s a post that I wrote about that https://wonderlaura.com/2019/07/23/powerapps-text-input-pattern-validation/
Thank you for sharing very much helps
can i ask is it possible to both approved and rejected into varstatus?
i am trying to put a All button and set Varstatus to have Pending/Approved/Reject.
Yes, sure, you can set a variable to anything you’d like.
Hi Laura. I have a Canvas app for a SharePoint list that contains a checkbox. There is a dropbox higher up in the form and if the user selects a particular value from the dropbox, I want the checkbox to be cleared out even if he/she checked it already. Is there a way to do this?
Yes, there’s a “reset” property on each control that you could place a variable in, to accomplish that.
Hi Laura. I’ve worked with Canvas apps a bit but struggle with the resetting of a field back to an ’empty’ value. I’m using the method as suggested in point 3. of your guidance (i.e. setting the Default for the Status field to be = If(IsBlank(varStatus), ThisItem.Status, varStatus) ) and am using this for a number of fields on my form and it works well normally. Under some circumstances I would then like to be able to then reset the ‘varStatus’ (and other) values to have no value/be empty so that it updates the field value when the record gets saved. Can you suggest how I can do this please?
If you use ‘ Set(varStatus, Blank()) ‘ this approach that won’t work because with the variable as blank, the default formula assumes there is nothing to update of course!. If you use ‘Set(varStatus, “”)’ than that also fails for the same reason.
Would it be possible to update the field somehow (based either upon a new variable such as ‘varRESET’ or similar, and then use that within an ‘If’ statement of the reset command? I’m really struggling over this one so any help would be greatly appreciated. Thanks in advance (hopefully) Alan C.