cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
bolin-stratus
Level: Powered On

Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

I am using a gallery and wondering if I can set a local variable using ThisItem syntax. I am able to successfully use ThisItem as shown below but I cannot figure out how to use it with a local variable.


// Wks

Set( varReturnedRecord, Patch( 'Red-Team-Reviewers', ThisItem, { Status: dropdownStatusReview.Selected, Comments: txtCommentsReview.Text } ) );


// syntax error - incorrect use of ThisItem
UpdateContext( { locThisItemStatusReview: ThisItem.dropdownStatusReview.Selected } );

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

Okay...so what I would do for this scenario is when they click the Save icon BEFORE it does the Patch or whatever you have that is making it save that data put:

 

UpdateContext({varStatus: DDStatus.Selected.Value}); UpdateContext({varComments: inputComment.Text});--then your Patch after that and change it back to view mode after and all that.

 

I have one that does basically this same process. HOWEVER, I use this in Canvas apps...not model driven. If this does not work as you need then you might have do the global variable instead.

View solution in original post

10 REPLIES 10
Super User
Super User

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

You can use ThisItem.Column in the Gallery. 

 

ThisItem is referring to what the value is at the data source. A dropdown is a value in the app so you can refer to the ThisItem.ColumnValue or you can set the variable off the dropdown selected value....either will work but not at the same time. One or the other. 

 

I hope this helps, let me know if I didn't explain it well enough. 

bolin-stratus
Level: Powered On

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

@rebeccas  Thanks for the quick response. I need to update a local variable to represent the value the user has selected before clicking save. I don't want to set the local variable to the current value in the data source. How do I set the current/selected drop down value using ThisItem using UpdateContext?

Super User
Super User

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

Just refer to the drop down instead. If it is in the gallery it will only take the value of that one line item's drop down selection. It basically is doing the same thing as ThisItem would do but you don't have to use that term. 

 

Let me know if you have any trouble

bolin-stratus
Level: Powered On

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

@rebeccas  - I have not been successful in figuring out a syntax that will work. Can you please provide an example?

Super User
Super User

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

There is a few ways you can do it:

 

1. Button - UpdateContext({varDD: Dropdown1.SelectedText})

Refer to: varDD.Value

 

2. Button - UpdateContext({varDD: Dropdown1.Selected.Value}

Refer to: varDD

 

Either will work..I prefer the second but for no reason particular

bolin-stratus
Level: Powered On

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

I already used that syntax with Patch:

 

Set( varReturnedRecord, Patch( 'Red-Team-Reviewers', ThisItem, { Status: dropdownStatusReview.Selected, Comments: txtCommentsReview.Text } ) );

 

However, referencing ThisItem in the UpdateContext function is not as easy. if possible at all.

 

// syntax error
UpdateContext( { locThisItemStatusReview: ThisItem.dropdownStatusReview.Selected } );

// syntax error
UpdateContext( ThisItem, { locThisItem: dropdownStatusReview.Selected } );

I must ref ThisItem when setting the local var. How would I do this? Please advise.

 

Super User
Super User

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

The only difference I have found between using Set() and UpdateContext() is Set will work on other screens and UpdateContext() only works for the current screen. Other than that they work pretty much the same.

 

ThisItem for sure won't work when referring to a dropdown because that is a given. 

 

If you are in the gallery (you are correct?) you can have either: 

UpdateContext({varSelected: ThisItem.Title}) -- that refers to the actual data source or collection 

 

or you can have

 

UpdateContext({varSelected: Dropdown1.Selected.Value}) -- if you want it set off the dropdown instead of the value in the gallery

 

That are the only two options to set a value in a gallery that I can think of whether you are using Set() or UpdateContext(). 

 

If I am misunderstanding what you are trying to do please let me know...it happens sometimes. 

bolin-stratus
Level: Powered On

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

I thought I might be able to get away with not showing the full scope of my app to focus in on the local var part but I should have been more thorough at the beginning.

 

My app allows the logged in user to edit an item in the gallery by clicking the EDIT/Pencil icon, which then reveals the SAVE icon. Then a user is allowed to change a Status dropdown as well as a Comments text input and either click save or "X" cancel. When Save is clicked, I will perform tasks in a modal window, one of which is send an email using an htmltext field. As a result, I need to set local vars for Status and Comments to the htmlText field so the data will be what the user selected and not the data source values reflected in the gallery prior to a save. Below are two screenshots. I am thinking I may have to write the "ThisItem" data to a collection for this purpose but that seems overly complicated. 

 

MyReviewAssignments SAVE.PNGMyReviewAssignments EDIT.PNG

Super User
Super User

Re: Can I Set a Local Variable Using ThisItem Syntax in a Gallery?

Okay...so what I would do for this scenario is when they click the Save icon BEFORE it does the Patch or whatever you have that is making it save that data put:

 

UpdateContext({varStatus: DDStatus.Selected.Value}); UpdateContext({varComments: inputComment.Text});--then your Patch after that and change it back to view mode after and all that.

 

I have one that does basically this same process. HOWEVER, I use this in Canvas apps...not model driven. If this does not work as you need then you might have do the global variable instead.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,455)