cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Prodigy
Post Prodigy

UpdateContext and Visibility

I have a couple questions. I have built a Time Off Request app for our employees. I made a PendingRequests Screen where the managers login to approve or deny requests. I used UpdateContext to update the Status column in my Excel depending of if they click Approve or Deny but nothing is populated in my Excel. Here is my OnSelect statement:

 

Office365.SendEmail(Email,"Time Off Request","Your time off request has been approved.");

UpdateContext({Status:"Approved"})

 

Second question is on Visibility, I have 3 screens: PendingRequests, ApprovedRequests, and DeniedRequests. So once a request is Approved or Denied, I want the request to only be visible on the appropriate Screen. So on Visible statement I tried:

 

If (Status = "Approved")

 

but it did not work, any help would be appreciated. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Responsive Resident
Responsive Resident

Re: UpdateContext and Visibility

If you have a dropdown

Switch(Status.Selected.Value,

"Approved", Colour,

"Rejected", Colour,

"Option3",Colour,

DefaultColour)

If you have a Text Column as source

Switch(Status,

"Approved", Colour,

"Rejected", Colour,

"Option3",Colour,

DefaultColour)

 

Regards

View solution in original post

21 REPLIES 21
Highlighted
Microsoft
Microsoft

Re: UpdateContext and Visibility

Hi thunter,

 

UpdateContext() is used to set a temporary variable on the current screen, that is local to that screen.  It will only update the variable in the PowerApps session, not update the source, (which in this case I'm assuming to be your Excel sheet).

 

To update the source, you need to either use an Edit form and a Submit() function, or a Patch() function.

 

If you use an Edit form, you can then also use the OnSuccess: property for the form to send your email, this makes sure it only sends the email if the update succeeds.

 

Assuming for now you're not using a form, your Patch() statement would look something like this;

Patch(ExcelSource, RowToUpdate, {Status: "Approved"})

where RowToUpdate is a function that returns the specific row you want to update - this may be a LookUp(), or, in the context of a Gallery item, assuming the button you're pressing is inside the Gallery item, you can just use ThisItem

 

As for the screens, you can't control whether a screen is 'visible' or not - only controls and elements on the screen carry this property.  If you're using a Gallery or something similar to display data on the screen, then you would typically just filter the data according to the Status for that Gallery on that screen - so a Gallery displaying data on your PendingRequests screen might have its Items: property set to;

Filter(ExcelSource, Status="Pending")

whereas on your ApprovedRequests screen the Gallery showing the data for that screen might have its Items: property set to;

Filter(ExcelSource, Status="Approved")

 

Not sure if this helps you, perhaps you can provide some screenshots for additional context to help determine the best solution?

 

Kind regards,

 

RT

Highlighted
Post Prodigy
Post Prodigy

Re: UpdateContext and Visibility

Thanks for your feedback. Yes, you are correct, I want to make the Gallery visible on the ApprovedRequests screen if the Status is Approved and visible on the DeniedRequests if the Status is Denied. I also tried to use UpdateContext({Status:"Approved"}) but it doesnt work. Is that where I would use the Filter command as you stated?

Highlighted
Microsoft
Microsoft

Re: UpdateContext and Visibility

Hi thunter,

 

Would it be possible to post some screenshots so I can get a better look at what we're dealing with? 🙂

 

Kind regards,


RT

Highlighted
Post Prodigy
Post Prodigy

Re: UpdateContext and Visibility

Highlighted
Super User
Super User

Re: UpdateContext and Visibility

You need to Patch the datasouce to actually change it, (Lookup Patch function in PowerApps).  UpdateContext just creates a temporary variable. In your case, you can use UpdateContext() to create a variable and set it to either true or false since the Visible property must equate to either true or false. So in the OnSelect property of the button the UpdateContext({approved:true}), Set the Visible property to "approved" (without the quotes).  If you want the Visible property of a form, control, label, etc. to hide when the screen opens, set the OnVisible property of the screen to UpdateContext({approved:false}).  Hope this helps.

Highlighted
Post Prodigy
Post Prodigy

Re: UpdateContext and Visibility

I read the document on the Patch function and here is what I tried:

Patch(PendingRequest_Table, Status, "Denied")

PendingRequest_Table is a Sheet in my Excel

Status is the Column I want updated

"Denied" is what I want to populate the column with

Highlighted
Microsoft
Microsoft

Re: UpdateContext and Visibility

Hi thunter,

 

Thanks for the screenshot 🙂

 

Your formula should work, assuming it's on the OnSelect: property of the Tick icon and the Tick icon is inside a gallery row and not on top of it or elsewhere in the screen hierarchy.  I also assume the data in the Gallery row is from the PendingRequestsTable?

 

What is the error on the Tick icon?

 

Kind regards,

 

RT

Highlighted
Post Prodigy
Post Prodigy

Re: UpdateContext and Visibility

Highlighted
Microsoft
Microsoft

Re: UpdateContext and Visibility

The format of your Patch() statement seems to have changed from the first pic.....but I see you have the cross selected now instead of the tick.

 

The correct format is 

Patch(source, record, {column: "value"})

can you update your Patch statement to 

Patch(PendingRequest_Table, ThisItem, {Status: "Denied"})

for the cross and 

Patch(PendingRequest_Table, ThisItem, {Status: "Approved"})

for the tick and then show what the error is?

 

Thanks 🙂

 

RT

 

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (10,549)