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

Assign patch to a variable

I have this reusable patch, and I don't want to put this patch in all of the buttons that I have.

 

I tried to do this in OnVisible of the screen

 

Set(varPatchInfo,  Patch(
            'SP-List-Data',
            LookUp(
                'SP-List-Data',
                'RefID' = txtRefID.Text
            ),
            {
                
                    'RefID': txtRefID.Text
                    ,'Number': txtNumber.Text
             }))

 

  

And in the OnSelect of my button, I call the variable varPatchInfo

 

but it doesn't work

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @akosila , 

I see what you want now, but you simply cannot “automate” or “store” an action in a Variable. You can however use the Select() statement to run the code from all buttons by using

Select(YourFirstButtonName)

and simply putting the Patch code on that button.

 

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.

View solution in original post

4 REPLIES 4
WarrenBelz
Super User III
Super User III

HI @akosila ,

I am not sure exactly what you are trying to do here, but you are Patching your list every time and setting the number (not a good name for a field - it is a Reserved Word in Power Apps - you might read this blog of mine) field to the value of a control and then setting a Variable to this value. The below is a shorter version of the same code.

Set(
   varPatchInfo,  
   Patch(
      'SP-List-Data',
      {'RefID': txtRefID.Text},
      {'Number': txtNumber.Text}
   )
)

 If you simply want to set a Variable to the record where RefID equals txtRefID.Text in the List 'SP_List_Data', then do this

Set(
   varPatchInfo,  
   LookUp(
      'SP-List-Data',
      'RefID'=txtRefID.Text
   )
)

 

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 @akosila ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

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 sorry, I am out for the past weeks.

 

What I want to do is to assign that whole patch statement so  I can just call the variable in my button.

(FYI, the 'Number' is a typo, it should be 'txtNumber')

Anyway, I have several "Save" buttons, and basically, they just need to patch the same thing, my worry is that when I need to update the patch statement, I need to modify ALL the buttons. 


But if I resolve this, I just need to modify my variable and all the button follows since they have that as their OnSelect.

 

Hi @akosila , 

I see what you want now, but you simply cannot “automate” or “store” an action in a Variable. You can however use the Select() statement to run the code from all buttons by using

Select(YourFirstButtonName)

and simply putting the Patch code on that button.

 

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.

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

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

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,417)