cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
snowboi
Regular Visitor

THE PATCH FUNCTION KEEPS GIVING ME DIFFERENT ERRORS

I am trying to use the patch function to update a column "Shelter status" from my "Animal Tables" table upon submitting a form. I keep getting the error in the image. please help.

9 REPLIES 9

Hey there,

 

So I tried and experimented for almost 2 days on using the patch function with a form and I discovered that they are not "friends". I also noticed that Patch function works with normal labels like a Text Input label. It is able to get the .Text from the label for example if you named your text input label SnowBoi, patch works with "SnowBoi.Text". It takes that and then adds it to the record you need it to be added to. See the screenshot below, you will see that the things I circled in red are text input labels. I made it look like a form instead of using a form.

 

In the picture below (Patch issue solved pt 2), you can see the app screen has 2 columns. The first column is indeed an editable form that I have made some parts of it view only. On the second column is the foster information that looks like a form but it is not a form. I just arranged it to look like that and then I used patch on the text labels as you can see in the other picture of where I circled things red (Patch issue solved).

 

I may be wrong too on the patch not working with forms but based on all I tried for the past almost 2 days, nothing worked with the form. Hopefully a better expert than myself can add more information on how to use patch with forms.

Patch('Animal Tables', {'Shelter Status': 'Shelter Status'.Form2.LastSubmit.(This should be the name of the column for option set i.e. the combobox)

I see what you did there. Thank you for providing this update. I had a hard time trying to use patch on  a form and then I decided to take another approach but thank you for sending this solution

snowboi
Regular Visitor

@ZeeScience Looking at the part2 patch solve solution you sent, How did you get both animal information and foster family information to show up on the same edit form?

Are they separate? If so, How did you apply the patch to them?

 

snowboi
Regular Visitor

@Rebecca-MSFT 

 

The combobox doesn't have an "On Success" parameter. What parameter should this patch be applied to if the combobox forms part of the reference?

 

Patch can go on the Form's OnSuccess property. You could also just add the combobox to your form and just use SubmitForm on the onselect property of the button.

snowboi
Regular Visitor

@Rebecca-MSFT 

 

I tried the methods above and it seems to present some issue.

I tried patching the combo box but it does not show "Last submit" as an option.

Please not that Form2 was renamed to FosterfamilyAppform which has details for the foster family information from the foster table.

When I tried to patch the foster family form it did not I could not bring up anything related to the Animals Table so that the patch could update the shelter status on the Animals Table.

What do you think I may be doing wrong?

 

Corry
Advocate V
Advocate V

Hi @snowboi,

 

I have setup a testing scenario to facilitate the updating of the Shelter Status.

My test scenario is as follows:

 

Data sources

Animal Table with 2 columns, 1 for Animal Name and another for Shelter Status.

Animal Name is the primary column and Shelter Status is a choice column with is getting the choices from a global choice set.

 

Model-driven app

I have a simple form with the animal name and status.

 

Canvas app

I have a gallery with the animal table as the data source with the animal name and status as displayed fields.

Next to the gallery is an edit form with the animal table as the data source with the animal name and status as displayed fields.

Below the edit form is a button, the OnSelect property of this button is set to SubmitForm(AnimalTableForm).

 

Corry_0-1716420948638.png

 

Testing 1

In my test, I change the dropdown (ComboBox) for the shelter status and the change is reflected in the gallery. This tells us that the 'Patch' method is not required to update a choice when used in this way.

 

Testing 2

Let's assume the Shelter Status column is not part of your canvas app edit form, but you still need to update this to "Claimed for Foster".

In my testing, I added this patch formula to the OnSelect property of the button.

 

Patch(
    'Animal Tables',
    LookUp(
        'Animal Tables',
        'Animal Table' = AnimalTableForm.LastSubmit.'Animal Table'
    ),
    {'Shelter Status': 'Shelter Status'.'Claimed for Foster'}
);
SubmitForm(AnimalTableForm)
This resulted in a successful patch of the Shelter Status.

 

Corry_1-1716421872216.png

 


Explanation
When patching in this way, it is really imported to use the correct references in the formula.

Here is how Copilot explains the formula

 

This expression updates the 'Shelter Status' field of a record in the 'Animal Tables' table with the value 'Claimed for Foster' for the record that matches the 'Animal Table' value of the last submitted record in the 'AnimalTableForm'. After that, it submits the changes made in the form.

 

Because this patch method is working with records, we need the Unique Identifier in our table as this holds the GUID specific to the last record submitted.

 

I will breakdown the formula.

 

  1. Patch('Animal Tables', - This is your table where the patch method is going to occur.
  2. Patch('Animal Tables',LookUp('Animal Tables', - Because we are patching to a record, we need to do a lookup within our table that we are patching to.
  3. Patch('Animal Tables',LookUp('Animal Tables','Animal Table' - 'Animal Table' at the end of this part of the formula is the 'Display Name' of the 'Unique Identifier' column in the table. This is the first part of looking for the record that was last submitted.
  4. Patch('Animal Tables',LookUp('Animal Tables','Animal Table' = AnimalTableForm.LastSubmit.'Animal Table'), - Now that we have the 'Display Name' of our 'Unique Identifier' column, we need to tell the 'LastSubmit' method the GUID that matches the last submitted record from the form. In this formula, I have used the Display Name of the Unique Identifier. When I place my cursor on this display name within my formula, I can see the GUID at the bottom as shown in the below image. This confirms to me that the lookup function has found the record.
  5. Corry_2-1716423588729.png
  6. Navigating to the table in our solution, we can also see the GUID.
  7. Corry_3-1716423786691.png
  8. Patch('Animal Tables',LookUp('Animal Tables','Animal Table' = AnimalTableForm.LastSubmit.'Animal Table'),{'Shelter Status': 'Shelter Status'.'Claimed for Foster'}); - Now that we have established, we can look up the record of the last submitted form, we need to set the parameters to update the Shelter Status column associated to that record. We simply define the column we are looking for, then call the column and its value.
  9. Patch('Animal Tables',LookUp('Animal Tables','Animal Table' = AnimalTableForm.LastSubmit.'Animal Table'),{'Shelter Status': 'Shelter Status'.'Claimed for Foster'});SubmitForm(AnimalTableForm) - We close out the OnSelect formula with the 'SubmitForm' method to ensure the columns that are present in the canvas app edit form are updated.
 

I hope this was helpful in providing a little more understanding around using patch, specifically for choice columns. I think it is also time well invested in setting up simple test scenarios to see how things work.

It is actually 2 different forms. I just edited it in such a way that it presents itself as one form

Helpful resources

Announcements

Important Update | Power Up Community READ ONLY July 22 – July 28

Dear Community Members, As you may have read, the Power Platform communities are transitioning to a new platform and to access will be set to READ-ONLY mode during the transition. Key DatesTo ensure current learners have adequate support in the final week of the cohort, the Power Up Program Community will transition to READ-ONLY mode starting July 22nd, the platform will transition to READ-ONLY mode until July 28th. Power Apps, Power Automate, and Power Pages communities will be read-only July 16-22, 2024.During this period, members will not be able to start new threads or Kudo, Comment, or Reply to any posts, but will be able to search and review past threads or solutions. On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities. Learners will be able to sign in to the new Power Up Program community experience, starting July 29th. If you registered for community using your learnwithpowerup account, you will not receive an email, but should be able to sign in successfully if you are signed in to My hub.  If you need help with your community account, please submit a request at aka.ms/PPCommSupport We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead! 

Learn what to expect in the Power Up Program

Since its inception in 2022, the Power Up Program has evolved based on feedback from learners and Microsoft Partners and customers. Today's Power Up learners can expect to learn the fundamentals of Microsoft Power Platform in the accelerated seven-week, video-based Power Up Maker course.   Hear from Principal Program Manager, Dimpi Gandhi to discover the latest enhancements and meet the Microsoft MVPs, Rory Neary and Charlie Phipps, who partnered with the Microsoft Power Up Program to create the Power Up Maker course to guide learners to use the Microsoft Power Platform to develop custom applications, build dazzling report dashboards, or create efficiencies through automation.  

Welcome to the Power Up Program Community

The Power Up Program is a free upskilling program where nontechnical people can learn the fundamentals of Microsoft Power Platform. The Power Up Maker course is a seven-week self-paced virtual learning plan that include video-based objectives featuring Power Apps, Power BI and Power Automate.  As a member of the Power Up Community, you can grow your skills and build connections. You can post questions to get help with the curriculum and hands-on exercises from experts and peers in the product boards.  Check out the Community Information & Feedback board to find help or provide feedback with the community experience, and please take time to post in the Social board to tell us more about yourself. If you're new to the Power Up Program and looking for information to register. You can sign up at PowerUp.Microsoft.com.

Users online (1,377)