cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MikeAnderson
Level: Powered On

Patch not updating multiple fields in a collection record

Hello,

 

I'm attempting to use Patch to update multiple fields in a record inside a collection. This collection will then be Patched to the datasource which is an Azure SQL database.  I haven't been able to successfully update multiple fields within the collection, but I am able to update a single field.

 

This works:

Patch(
    PendingEquipmentRequestsCollection,
    First(
        Filter(
            PendingEquipmentRequestsCollection,
            ID = PendingEquipmentGallery.Selected.ID
        )
    ),
    {
        IsDeleted: true,
    }
);

This does not:

Patch(
    PendingEquipmentRequestsCollection,
    First(
        Filter(
            PendingEquipmentRequestsCollection,
            ID = PendingEquipmentGallery.Selected.ID
        )
    ),
    //LookUp(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID),
    {
        IsDeleted: true,
        ModifiedDate: Now(),
        ModifiedBy: varCurrentUser.Email
    }
);

I can't figure out why I can't update more than one field in the collection record. Any suggestions?

 

4 REPLIES 4
shailendra74
Level 8

Re: Patch not updating multiple fields in a collection record

Hi @MikeAnderson 

 

I dont' see any issue in the code you shared.

 

Can you refresh the datasource and also ensure that the collection has all fields mentioned in the update and the datatype are matching.

 

Thanks.

MikeAnderson
Level: Powered On

Re: Patch not updating multiple fields in a collection record

Nor do I :-).  I tested a few more things and have found the following odd behavior.  Here is the collection before modification:

BeforeSave.png

Here is the patch code:

 

Patch(
   PendingEquipmentRequestsCollection,
    First(
        Filter(
            PendingEquipmentRequestsCollection,
            ID = PendingEquipmentGallery.Selected.ID
        )
    ),
    {
        IsDeleted: true,
        ModifiedDate: Now(),
        ModifiedBy: varCurrentUser.Email
    }
);

Here is the result after the patch code runs:

 

AfterSave.png

 

What makes this even more interesting is that if I remove the collection and patch directly against the database, IT WORKS!

 

Patch(
 '[dbo].[EquipmentRequests]',  //This is the azure sql db data source
    First(
        Filter(
            PendingEquipmentRequestsCollection,
            ID = PendingEquipmentGallery.Selected.ID
        )
    ),
    //LookUp(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID),
    {
        IsDeleted: true,
        ModifiedDate: Now(),
        ModifiedBy: varCurrentUser.Email
    }
);

And here you can see the record was modified:

 

DatasourceSave.png

 

So, I'm even more befuddled now.  It works against the data source, but not against the collection and I have no idea why.

shailendra74
Level 8

Re: Patch not updating multiple fields in a collection record

Hi @MikeAnderson 

 

Can you run below code separately to check which field is causing a problem.

 

 

 

Patch(
 PendingEquipmentRequestsCollection,  //your collection
    First(
        Filter(
            PendingEquipmentRequestsCollection,
            ID = 4 //hardcoded here
        )
    ),
    //LookUp(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID),
    {
        IsDeleted: true,
        ModifiedDate: Text(Now(), "mm-dd-yyyy") // change the format
        // ModifiedBy: varCurrentUser.Email // commented
    }
);

 

 

 

 

Patch(
 PendingEquipmentRequestsCollection,
    First(
        Filter(
            PendingEquipmentRequestsCollection,
            ID = 4 //hardcoded here
        )
    ),
    //LookUp(PendingEquipmentRequestsCollection, ID = PendingEquipmentGallery.Selected.ID),
    {
        IsDeleted: true,
        // ModifiedDate: Text(Now(), "mm-dd-yyyy") //commented
        ModifiedBy: "testmail.com" // hardcoded
    }
);

 

Thanks

Highlighted
MikeAnderson
Level: Powered On

Re: Patch not updating multiple fields in a collection record

Thank you for the suggestion. Due to some app redesign changes I haven't been able to test your suggestion but will and report back.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 244 members 5,348 guests
Please welcome our newest community members: