cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tommyly
Responsive Resident
Responsive Resident

Question about Context Variables and Clearing an Object Data Type

This is one of those weird questions where it may have already been discussed, but hidden behind unexpected subject terms. If this is the case, can you please supply a link? Thanks.

 

So I've been playing around with the idea of assigning objects to context variables (as well as collection fields). For example:

 

UpdateContext(myContextVariable, First(Filter(myCustomerSPList, ID=100)))

 

Once I've assigned myContextVariable to this item, I can refer to my customer as myContextVariable.FirstName. This is my intention. Now, I run some subsequent filters based on this data, so at some point, I'd like to clear out this data.

 

If I type in Clear(myContextVariable), I get an error because it's not a "collection" data type. If I type UpdateContext(myContextVariable, ""), I also get an error because it's not a "text"  data type. It's an "object" data type. How do you clear that? Thanks.

 

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-updatecontext

1 ACCEPTED SOLUTION

Accepted Solutions
Scobie
Advocate II
Advocate II

Hi @tommyly

 

This was interesting as I hadn't thought much about a context variable being a object or record type. 

 

To Clear this value for the vaiable you can make use of the Blank() function . As shown here:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-isblank-isempty

 

using the syntax:

UpdateContext({myContextVariable: Blank()})

 

Scobie

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi tommyly

 

Interesting that your function below worked as well. 

UpdateContext(myContextVariable, First(Filter(myCustomerSPList, ID=100)))

I usually work with the following syntax as indicated in the documentation site you referred to: 

UpdateContext( { ContextVariableValue})

 

This would suggest that updating your context variable may be possible using:

UpdateContext ( { myContextVariable: "" } )
Scobie
Advocate II
Advocate II

Hi @tommyly

 

This was interesting as I hadn't thought much about a context variable being a object or record type. 

 

To Clear this value for the vaiable you can make use of the Blank() function . As shown here:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-isblank-isempty

 

using the syntax:

UpdateContext({myContextVariable: Blank()})

 

Scobie

View solution in original post

tommyly
Responsive Resident
Responsive Resident

That seems to do the job. Thanks!

salvadorplj
Regular Visitor

The safest way to clear a variable is by being explit about the data type you hold in it, that way you wont have any issues if processes' steps intermix.


Instead of:

UpdateContext({SunShine: Blank()});

Do: 

UpdateContext({SunShine: DateTimeValue(Blank())});

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors
Users online (3,457)