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

Patching multiple records - patch successful but return variable empty

I am patching multiple records to a SharePoint list with one statement and attempting to set the return variable.

 

ClearCollect(_returnVar, Patch('Data Source', _patchBaseRecords, DropColumns(_patchRecords, "unneededField1", "unneededField2")));

 

 Unfortunately, despite the patch successfully posting records to the SharePoint list, _returnVar remains an empty variable.

 

Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Advocate II
Advocate II

I've discovered the solution. It seems there were more records in my _patchBaseRecords than there were in my _patchRecords.

 

This disparity may have been what caused the _returnVar to be empty, since fixing it has the Patch returning the table of new records as expected.

 

Thanks.

View solution in original post

5 REPLIES 5
Highlighted
Solution Supplier
Solution Supplier

Hi @denglish 

 

I assume you just would like to know whether the patch has been successful or not, right?

If so, I'd simply add a variable before your ClearCollect.

 

Set(gblError,
    ClearCollect(
        _returnVar, 
        Patch(
            'Data Source', 
            _patchBaseRecords, 
            DropColumns (
                _patchRecords, 
                "unneededField1", 
                "unneededField2"
            )
        )
    )
)

 

Then check against your gblError variable

If(
        Not(IsBlank(gblError)) And IsEmpty(Errors('Data Source')),
        // if successful
        ,
        // if not successful
);

 

I hope this helps.

 


Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.

Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.
Highlighted

Thanks, @FabianAckeret. Unfortunately, I am looking to retrieve the Data Source generated fields from the records created by the Patch. According to the documentation, Patch should be returning a table. I think this is a bug.

 

"Instead of passing a single base record, a table of base records can be provided in the second argument. Change records are provided in a table as well, corresponding one-for-one with the base records. The number of records in each change table must be the same as the number of records in the base table.

 

When using Patch in this manner, the return value is also a table with each record corresponding one-for-one with the base and change records."

-https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

Highlighted

Hi @denglish 

 

The table being returned would be your _returnVar. Is it empty?

Also, what do you have in _patchBaseRecords?

 

I have never used Patch like this, but there must be some magical matching behind the scenes to know which records to be matched with the ones in _patchRecords. I think this might be the ID. You mentioned:

Unfortunately, despite the patch successfully posting records to the SharePoint list, _returnVar remains an empty variable.

Are only new records being created or the ones in _patchBaseRecords updated?

 

Kind regards,


Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.

Please click Accept as Solution if my post answered your question. Like my answer? Consider giving it a Thumbs Up. Others seeking the same answers will be happy you did.
Highlighted

Yep, you've got it, @FabianAckeret_returnVar being empty is my issue. The Patch is working exactly as expected, except for the assignment statement yielding an empty table instead of a table of records corresponding one-for-one with the base and change records.

 

My _patchBaseRecords contains the same number of records as my _patchRecords. Since I want all the records in _patchRecords to create a new record in the Data Source, all the records in _patchBaseRecords are set to Defaults('Data Source').

 

According to the documentation, the matching is done one-to-one between the records in the second and third arguments of Patch:

"Patch can also be used to create or modify multiple records with a single call.

Instead of passing a single base record, a table of base records can be provided in the second argument. Change records are provided in a table as well, corresponding one-for-one with the base records. The number of records in each change table must be the same as the number of records in the base table.

When using Patch in this manner, the return value is also a table with each record corresponding one-for-one with the base and change records."

from https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

 

Highlighted
Advocate II
Advocate II

I've discovered the solution. It seems there were more records in my _patchBaseRecords than there were in my _patchRecords.

 

This disparity may have been what caused the _returnVar to be empty, since fixing it has the Patch returning the table of new records as expected.

 

Thanks.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,355)