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

Struggling with Patch; Gallery to Collection to DataSource

I have an app that will allow a purchasing officer to update items as they are ordered from suppliers.

The requested feature is to allow the PO to update the status on a batch of records. Currently I'm using a checkbox on each record in the gallery, the checkbox adds or removes the record from the "CheckedItems" collection, a dropdown above the gallery has the possible statuses and uses UpdateIf to change the status of the records in the collection, after that the user presses a button to Patch those records to the CDS datasource. I'm getting the error createdby column is read only. How do I Patch a whole record to CDS?

Checkbox functions:

OnCheck, Collect(CheckedItems, ThisItem)

OnUncheck, Remove(CheckedItems, ThisItem)

Dropdown:

OnChange, UpdateIf(CheckedItems, !IsBlank(CheckedItems), {'Requested Part Status': BulkStatusBox.Selected.Status})

BulkStatusUpdate Button:

OnSelect: Patch('Requested Supplier Parts', CheckedItems)

 

Recieved Error:

createdby: The specified column is read-only and can't be modified.

 

10 REPLIES 10
Dual Super User
Dual Super User

Re: Struggling with Patch; Gallery to Collection to DataSource

Created, createdby, modified, and modified by are all columns that are controlled by the system and therefore can't be edited.  YOu can either filter them out when you are getting the records in the datasource or only submit the fields that need to be changed when doing your patch.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Super User
Super User

Re: Struggling with Patch; Gallery to Collection to DataSource

Try Collect(datasource, collection) instead of patch. If that gives you the same error then use DropColumns to get rid of the offending columns.
Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training
Community Support Team
Community Support Team

Re: Struggling with Patch; Gallery to Collection to DataSource

Hi @DevinFlickinger ,

 

Can you please share the formula that is related to updating the field "CreatedBy"? Like @Pstork1  said, this field is auto-generated by system and you shouldn't include it while updating.

 

Regards,

Mona

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
DevinFlickinger
Level: Powered On

Re: Struggling with Patch; Gallery to Collection to DataSource

@ShanescowsI switched it from Patch to Collect, no error thrown, but still unsuccessful at updating the CDS data. DropColumns also doesn't seem to be dropping the columns from the collection. To be safe I included all the CDS generated columns. I assume they are undroppable because they are seen as "read-only". My guess is since I add the entire record to the Collection from the Gallery that it tries to maintain the structure of that data including making those columns uneditable.

DropColumns(CheckedItems, "createdby","createdon","createdonbehalfby","importsequencenumber","modifiedby","modifiedon","modifiedonbehalfby","overriddencreatedon","owningbusinessunit","owningteam","owninguser","statecode","statuscode","timezoneruleversionnumber","utcconversiontimezonecode","versionnumber")

@v-monli-msft @Pstork1 So the OnCheck function adds the whole record from the Gallery(essentially straight from CDS as is) to the Collection. Then the Patch Function takes those records(with a change made to a single text field) and tries to update CDS with that change. Patch is what throws the error since it ( I assume ) attempts to write/update the createdby (and other autogenerated) field and therefore errors.

DevinFlickinger
Level: Powered On

Re: Struggling with Patch; Gallery to Collection to DataSource

@ShanescowsI switched it from Patch to Collect, no error thrown, but still unsuccessful at updating the CDS data. DropColumns also doesn't seem to be dropping the columns from the collection. To be safe I included all the CDS generated columns. I assume they are undroppable because they are seen as "read-only". My guess is since I add the entire record to the Collection from the Gallery that it tries to maintain the structure of that data including making those columns uneditable.

DropColumns(CheckedItems, "createdby","createdon","createdonbehalfby","importsequencenumber","modifiedby","modifiedon","modifiedonbehalfby","overriddencreatedon","owningbusinessunit","owningteam","owninguser","statecode","statuscode","timezoneruleversionnumber","utcconversiontimezonecode","versionnumber")

@v-monli-msft @Pstork1 So the OnCheck function adds the whole record from the Gallery(essentially straight from CDS as is) to the Collection. Then the Patch Function takes those records(with a change made to a single text field) and tries to update CDS with that change. Patch is what throws the error since it ( I assume ) attempts to write/update the createdby (and other autogenerated) field and therefore errors.

 

If I try to only include the needed columns in the Collect function on the OnCheck handler I get the error "Cannot use non-record value in this context." So I can't pick and choose which columns to add to the collection. As stated above I can't seem to drop the columns from the collection prior to the Patch function.

Dual Super User
Dual Super User

Re: Struggling with Patch; Gallery to Collection to DataSource

When you do patch and supply the specific column values do you do it in the form of a record?  ie 

{fieldname:"value",fieldname2:value}

If you don't supply the values in the form of a record that's when you will get the error you mentioned.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
DevinFlickinger
Level: Powered On

Re: Struggling with Patch; Gallery to Collection to DataSource

@Pstork1 

Gotcha, I've never seen that error before. I am supplying it in the form of a record. First it was Collect(CheckedItems, ThisItem). So from a checkbox on a Gallery item I can't add values of that item to the collection. I'm essentially doing Collect(CheckedItems, {CollectionFieldName: ThisItem.FieldNameFromCDS}

Dual Super User
Dual Super User

Re: Struggling with Patch; Gallery to Collection to DataSource

That should work unless you've already added the CDS data to the collection.  If that's the case then the collection already knows about the other fields and which ones are marked as required. So when you try to add a record with only one field it doesn't match.

 

The point is if you add system fields like Created and CreatedBy to the collection then you can't just submit the collection records in the patch statement.  YOu need to submit a record that only includes the non-system requried fields and the ones you want updated.  You can do that by not adding the system fields to the collection when you pull it from CDS or by stripping them out of the record before you send it to CDS with the Patch.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
DevinFlickinger
Level: Powered On

Re: Struggling with Patch; Gallery to Collection to DataSource

So taking your advice, I switched up how I was adding the record to a collection.

Now the Oncheck Function:
Collect(CheckedItems, {
cr546_requestedpartstatus: BulkStatusBox.Selected.Status,
cr546_jobcategory: 'Job Category',
cr546_noteforrequestedsupplierpart: 'Note for Requested Supplier Part',
cr546_noteforrequester: 'Note for Requester',
cr546_partdescription: 'Part Description',
cr546_partsrequest: 'Parts Request',
cr546_partsrequestnumber: 'Parts Request Number',
cr546_price: Price,
cr546_quantity: Quantity,
cr546_requestedpartid: 'Requested Part ID',
cr546_requestedsupplierpartid: 'Requested Supplier Part',
cr546_supplier: Supplier,
cr546_supplierpartnumber: 'Supplier Part Number',
cr546_unitofmeasure: 'Unit Of Measure'
})

Collecting everything I care about into the collection. So now when Patching this...

ForAll(CheckedItems, Patch('Requested Supplier Parts', {cr546_requestedpartid:cr546_requestedpartid}, {
cr546_requestedpartstatus: BulkStatusBox.Selected.Status,
cr546_jobcategory: cr546_jobcategory,
cr546_noteforrequestedsupplierpart: cr546_noteforrequestedsupplierpart,
cr546_noteforrequester: cr546_noteforrequester,
cr546_partdescription: cr546_partdescription,
cr546_partsrequest: cr546_partsrequest,
cr546_partsrequestnumber: cr546_partsrequestnumber,
cr546_price: cr546_price,
cr546_quantity: cr546_quantity,
cr546_requestedpartid: cr546_requestedpartid,
cr546_requestedsupplierpartid: cr546_requestedsupplierpartid,
cr546_supplier: cr546_supplier,
cr546_supplierpartnumber: cr546_supplierpartnumber,
cr546_unitofmeasure: cr546_unitofmeasure
}))

The Columns cr546_supplier and cr546_partsrequest are lookup columns creating relationships with other entities, so now i'm recieving the error "The specified column, cr546_supplier doesnot exist"

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (4,120)