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.

 

Thanks
Stalin

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

 

Thanks
Stalin

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.

 

Thanks
Stalin

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.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

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.

Top Solution Authors
Top Kudoed Authors
Users online (1,633)