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

Patch function not working updating dataverse table

Hi!

 

I'm having trouble updating a Dataverse table with data from a collection using the PATCH function. My Dataverse table has multiple columns, but through the app I only need to update two columns. Here's the code I'm using.

 

DistrictGoals is my datasource from Dataverse, and colDistEditRecords is a collection I created that holds the records I need to update on the datasource. cr8d6_name is the id column and the other two columns are the ones I need to update. I have this on a button. As soon as I run it, it gives me an error saying that another column is needed in the collection.

 

Patch(
DistrictGoals
, ShowColumns(
colDistEditRecords
, "cr8d6_name"
, "cr8d6_comments"
, "cr8d6_edit_plan"
)
)

 

I tried creating a test collection directly from the datasource, but the result was the same. I'm sending an image of the script and the error that shows when hovering over it. And a second image with the error after adding the "missing" column. Hope you guys can help me!

nramirez03_0-1626924997165.png         

Image 2. Same error after adding "cr8d6_uid" to the collection.

nramirez03_1-1626925119951.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Community Champion
Community Champion

Hi @nramirez03 

 

We have to use a patch with Forall 

 

 

 

ForAll(Gallery3.AllItems,
	Patch(
    	Datasource,
    	LookUp(Datasource,ID = textinput1.Text),
    	{
        	Title: textinput3.Text,
        	'Issue description': DataCardValue10.Text
    	}
	)
)

 

 

 

Improve Speed:

 

Method: Patch the record(s) only modified instead of all gallery items

 

Steps to do:

  • Collect the data in a collection whenever data changed in a record
    • If any value is updated on the row, insert it into a collection
  • Now the collection has only the records thats updated
  • Button Onsubmit loop through the collection instead of all gallery items

Patch using collection instead of Gallery:

 

ForAll(
    NewCollection,
    Patch(
        'Issue tracker',
        {
            ID: ThisRecord.ID,
            'Issue description': ThisRecord.'Issue description'
        }
    )
)

 

 

If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

 

View solution in original post

3 REPLIES 3
StalinPonnusamy
Community Champion
Community Champion

Syntax:

 

 

Patch(
    Datasource,
    If(
        EditForm1.Mode = FormMode.New,
        Defaults(DataSource),
        LookUp(
            Datasource,
            ID = SelectedId
        )
    ),
    {
        Field list to update with comma separator
    }
);

 

 

Working Sample:

 

Patch(
    'Issue tracker',
    If(
        EditForm1.Mode = FormMode.New,
        Defaults('Issue tracker'),
        LookUp(
            'Issue tracker',
            ID = SelectedId
        )
    ),
    {
        Title: DataCardValue9.Text,
        'Issue description': DataCardValue10.Text
    }
);

 

  • We can assign a value(s) from collection to patch command

 

Thank you so much for your reply! Sorry, but I'm a bit confused on how to implement your script. In my case, I need to bulk update multiple rows. I was using ForAll and Patch, but going record per record takes forever (40+ seconds). Please correct me if I'm wrong, but I'm thinking your script works when working with one record at a time? I can't seem to make it work on my end.

 

 

StalinPonnusamy
Community Champion
Community Champion

Hi @nramirez03 

 

We have to use a patch with Forall 

 

 

 

ForAll(Gallery3.AllItems,
	Patch(
    	Datasource,
    	LookUp(Datasource,ID = textinput1.Text),
    	{
        	Title: textinput3.Text,
        	'Issue description': DataCardValue10.Text
    	}
	)
)

 

 

 

Improve Speed:

 

Method: Patch the record(s) only modified instead of all gallery items

 

Steps to do:

  • Collect the data in a collection whenever data changed in a record
    • If any value is updated on the row, insert it into a collection
  • Now the collection has only the records thats updated
  • Button Onsubmit loop through the collection instead of all gallery items

Patch using collection instead of Gallery:

 

ForAll(
    NewCollection,
    Patch(
        'Issue tracker',
        {
            ID: ThisRecord.ID,
            'Issue description': ThisRecord.'Issue description'
        }
    )
)

 

 

If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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