cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate II
Advocate II

Using global variable inside of patch function

Scenario:

  • I'm using Global variable HouseChoice to set which Sharepoint record is being worked on across screens
  • Sharepoint List = HouseList
  • Houselist record's field to be updated = ProgressTotal
  • Choosing which record to update depends on global HouseChoice
  • As TextInput fields change, 10 is to be added to ProgressTotal to represent 10% completion for each step, using OnChange

 

Problem:

 

I'm failing to write a correct Patch function that will effectively update the Sharepoint records with a Current Value + 10.

 

Here is an example of a patch function: for reference purposes. 

 

Patch( Customers, First( Filter( Customers, Name = "Contoso" ) ), { Phone: "1-212-555-1234" } )

 

14 REPLIES 14
Super User III
Super User III

Hi @Sacred_Totems ,

If I am reading this correctly, the Variable HouseChoice is a single record from the SharePoint list HouseList and you want to add 10 to the field ProgressTotal in the list HouseList in the record that is currently set in HouseChoice? Something like this should do it

UpdateIf(
   HouseList,
   ID=HouseChoice.ID
   {ProgressTotal:ProgressTotal+10}
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

@WarrenBelz thank you, and good afternoon,

 

It seems to me PowerApps is not recognizing .ID

What is ID ?

 

HouseChoice is a global variable.  I am getting the impression you are saying I can make an entire record a global variable. Is that correct?

 

Currently this is how I am setting House choice globally inside of a dropdown OnChange

 

Set(HouseChoice,'IP House Selection PD'.SelectedText.Value)

 

OK @Sacred_Totems ,

The first statement in your post was 

I'm using Global variable HouseChoice to set which Sharepoint record is being worked on across screens

This suggested you were using the Variable to contain the record.

Now you have qualified that HouseChoice is actually a single text value (it actually should be as below with Selected.Value)

Set(
   HouseChoice,
   'IP House Selection PD'.Selected.Value
)

Firstly to answer your question on ID, this is the unique identifier set automatically by SharePoint on every list and is an incremental number starting at 1 for the first record saved.

Secondly, you should be able to Update using the field that HouseChoice is being selected from - you have not given me the name of it - I will use YourHouseField (change to your name).

UpdateIf(
   HouseList,
   YourHouseField=HouseChoice
   {ProgressTotal:ProgressTotal+10}
)

I am assuming that this field comes from HouseList.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @Sacred_Totems ,

Do you want to filter based on  HouseChoice and then update this record's  ProgressTotal+10?

Actually, I agree with @WarrenBelz  in most of aspects. But there're still many uncertain places that I want to ask you.

Could you tell me

1)what is  'IP House Selection PD'?

2)the items of 'IP House Selection PD'?

3)how do you find the record to update based on HouseChoice?

4)the field's data type that is related to  HouseChoice?

I assume that:

 'IP House Selection PD' is a drop down, its Items: Choices(HouseList.HouseChoice)

There's a filed named HouseChoicefield, data type is choice.

You could filter list based on HouseChoicefield.

If so, you just need to:

1)set the variable like this:

Set(HouseChoice,'IP House Selection PD'.SelectedText.Value)

use formula like this to update:

UpdateIf(
   HouseList,
   HouseChoice.Value=HouseChoice
   {ProgressTotal:ProgressTotal+10}
)

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-yutliu-msft for confirming my thoughts.

@Sacred_Totems please confirm if this code works for you.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz 

 

In response to your reply containing the following:

Set(
   HouseChoice,
   'IP House Selection PD'.Selected.Value
)

 

I had tried that originally but it caused errors, but SelectedText as shown in the following does work and has proven effective for what I need:

 

Set(
HouseChoice,
'IP House Selection PD'.SelectedText.Value
)

@v-yutliu-msft 

 

1)what is  'IP House Selection PD'? -

A) A single selection dropdown

 

2)the items of 'IP House Selection PD'?

A) The items are the HouseList Title values

 

3)how do you find the record to update based on HouseChoice?

A)  OnChange of 'IP House Selection PD' is Set(HouseChoice,'IP House Selection DB_1'.SelectedText.Value)

 

4)the field's data type that is related to  HouseChoice?

A) Text

 

 

When I try putting the below into OnChange of TextInput fields I get an error code stating Invalid Argument.

 

UpdateIf(
   HouseList,
   HouseChoice.Value=HouseChoice
   {ProgressTotal:ProgressTotal+10}
)

 

 

This formula won't work though.  Since the Update should happen only if the TextInput's field value is not blank.  So I will have to change the HouseList record to match the TextInput, and then +10. 

 

 

@Sacred_Totems ,

We can both help you here - please tag whoever you want to continue the thread with as three way conversations just confuse everyone,

@WarrenBelz 

 

I would like to work with you on solving this if we can.   The purpose of this is to make record of what percentage of the over all processes have been completed.  So the Update should happen only if the TextInput's field value is not blank. 

 

So upon I will have to change the HouseList record to match the TextInput if it is not blank, and then +10 to the progress. 

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (12,866)