cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
camer314
Helper I
Helper I

How to update a field in a single record structure

I have seen several people ask this question but it seems they all have records that are part of a collection. What I have is a very simple record. In fact its a json representation so there are records within records etc.

 

I would have thought the most basic of functionality would exist to update a field in the record by reference but it appears that it cannot be done, at least not using PATCH, or I dont know how to use PATCH to reference a record that is not part of a datasource?

 

In any event this is the structure of my record in part:

 

Capture.PNG

So how do I go about updating the value for 'Agent'? Structurally that is equal to quoteRequest.'Policy Details'.Agent however I cannot figure out how to target that field, or generally any field in a record without it being in a collection.

 

This does not get a syntax error nor does it amend the record: 

 

Patch(quoteRequest, quoteRequest.'Policy Details', { Agent: "XXX"})

 

What I have is a UI that has controls that map to the fields in this JSON, so the JSON is read, it becomes a nested record, the controls are populated from the values, but I want to be able to update the values as the user changes the inputs.

1 ACCEPTED SOLUTION

Accepted Solutions

The only way to achieve this is to create a collection from the record, patch the collection and then reset the record from the collection. Seems like a very expensive and cumbersome solution but at least it is a solution.

 

// Turn the record into a collection, patch it then get the record back out
ClearCollect(tempdatasource, policyDetailsRecord);
Patch(tempdatasource, First(tempdatasource), {PolicyNo: Self.Text});
Set(policyDetailsRecord, First(tempdatasource));

 

I don't understand why the patch cannot work directly on a record, I would imagine the codebase is 95% there already, seems like an oversight if you ask me but for now if anyone else has the same problem the above works.

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

HI @camer314 ,

This would be the structure for Patching from inside a Form or Gallery ThisItem would be replaced with the record reference otherwise

Patch(
   quoteRequest,
   ThisItem,
   {
      'Policy Details':{Agent:"XXX"}
   }
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Thanks @WarrenBelz , the update is not from with a Form or Gallery and I dont know how to get the 'record reference' otherwise because its a single record not a collection.

Hi @camer314 ,'

I assume this is SharePoint - if you have only created one record, it will be ID 1, so

Patch(
   quoteRequest,
   {ID:1},
   {
      'Policy Details':{Agent:"XXX"}
   }
)

If not 1, get the ID from the record and use that.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

@WarrenBelz ,

 

No the record represents returned JSON from a custom connector web API, it does not originate from CDS nor is it a table or a collection, it is simply a JSON object that PowerApps has converted into a nested record variable from which PATCH does not seem to know what to do with.

@camer314 ,

OK - you are correct - Patch will have no idea what to do with it.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

The only way to achieve this is to create a collection from the record, patch the collection and then reset the record from the collection. Seems like a very expensive and cumbersome solution but at least it is a solution.

 

// Turn the record into a collection, patch it then get the record back out
ClearCollect(tempdatasource, policyDetailsRecord);
Patch(tempdatasource, First(tempdatasource), {PolicyNo: Self.Text});
Set(policyDetailsRecord, First(tempdatasource));

 

I don't understand why the patch cannot work directly on a record, I would imagine the codebase is 95% there already, seems like an oversight if you ask me but for now if anyone else has the same problem the above works.

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,575)