cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
abcrandy
Helper I
Helper I

How can I use a global variable whose value is determined by a conditional if statement and submit it to an existing field in a SharePoint list

I've struggled to get this button to update the Status field in my sharepoint list. The Status field has a default value of "Submitted". I want to use a button to update the Status field to show "Assigned" if DataCardValue21.Selected.Email contains data.

 

The first line of code does the conditional statement and sets the Global variable "varStatus" to the correct value. The Patch statement is where I'm running into trouble. If anyone can help I'd greatly appreciate it.

 

 

abcrandy_0-1598497529454.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Then your patch should look like this, you don't need the variable. 

 

If( DataCardValue34.Selected.Value = "Submitted" && (IsBlank(DataCardValue21.Selected.Email || IsEmpty(DataCardValue21.Selected.Email)  ,Patch(Intake,
LookUp(Intake, ID = DataTable1_1.Selected.ID),
{ Status: {
Value: "Assigned",
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"}
}
))
)

View solution in original post

15 REPLIES 15
PowerAddict
Super User
Super User

Not sure exactly what error message you are getting, but it seems like you are not passing any record to the Patch function. DataCardValue34 seems to be the status data card. What is the record that you are trying to update? 

 

Based on that your formula will look something like this: 

Patch(Intake, SelectedRecord, {Status: varStatus})

 

Let me know if this helps. 

 

---
If you like this reply, please give kudos (Thumbs Up). And if this solves your problem, please mark this reply as a solution by selecting Accept as Solution. This makes it easier for others to find answers to similar questions. 

 

Thanks!

Hardit Bhatia

Microsoft Business Applications MVP

Blog | Twitter | LinkedIn | Facebook | YouTube  |  Email

@PowerAddict thanks for your prompt response. I'm still learning Powerapps so I'm not sure how to identify the record or the syntax needed. My app contains a datatable and a form. The data table contains an ID column and I'm able to scroll /click on the different ids to see the detailed data for each record. I've attached a screenshot of the app. I'm assuming the record will be dictated by the ID field.

No problem. Try something like this: 

Patch(Intake, LookUp(Intake, ID = Gallery.Selected.ID), {Status: varStatus})

Let me know if this helps. 

 

---
If you like this reply, please give kudos (Thumbs Up). And if this solves your problem, please mark this reply as a solution by selecting Accept as Solution. This makes it easier for others to find answers to similar questions. 

 

Thanks!

Hardit Bhatia

Microsoft Business Applications MVP

Blog | Twitter | LinkedIn | Facebook | YouTube  |  Email

 

Please not. If your status column is a choice )dropdown) column you need to use the following format to update the value in a patch.
{Status:
{
Value: "Assigned",
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference"}
}
)

@cwebb365 from the previous posts, it doesn't seem like the status field is an option set. So I wouldn't shut down previous replies in the thread in an outright manner but thanks for your input anyways. 

 

Thanks,

Hardit

Shut down? I’m simply giving a tip to help when the most likely scenario will happen because most people use a drop down in a status field.

It was supposed to say “Please note.” To start not “Please not” mobile auto correct got that one.

All good my friend, and apologies for the misunderstanding. 

 

Thanks,

Hardit

 

 

@cwebb365 . The status field is a dropdown however I don't think the code you provided works for me since the value is based off of a condition. Below is the actual onSelect logic.

 

Note, my sharepoint list name is 'Intake', the field that I'm looking to update is named 'Status'. I'm using a global variable named varStatus to determine the value needed when updating the Status field. I believe my error is occurring with the second parameter for the patch statement.

 

If(DataCardValue34.Selected.Value = "Submitted" && IsBlank(DataCardValue21.Selected.Email) = false, Set(varStatus,"Assigned"));

Patch(Intake,
LookUp(Intake, ID = Select.ID),
{
Status:varStatus,
}
)

@PowerAddict My app doesn't use a gallary so the provided code isn't working. I'm using a form, a data table, and drop downs.

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,709)