I have a PCF with a dataset configured for a canvas app. I am trying to update the records in the dataset using record.setValue() followed by record.save(). After record.setValue() executes I have confirmed that my record.isDirty() == true. When I proceed to record.save(), I get an error. Has anyone been able to successfully execute record.save() in a canvas app or do you know what this error is?
TypeError: Cannot read properties of undefined (reading 'patchAsync')
at e.<anonymous> (pa.core.bundle1.js:11:317880)
at pa.core.bundle3.js:69:460357
at Object.next (pa.core.bundle3.js:69:460463)
at pa.core.bundle3.js:69:459397
at new c.Class.derive._oncancel (base.js:2:44584)
at new e (pa.core.bundle3.js:69:600665)
at l (pa.core.bundle3.js:69:459171)
at e.@pa-client/appmagic-runtime-app.e.save (pa.core.bundle1.js:11:317690)
at ResultItemVM.eval (ResultItemVM.ts:159:22)
at Generator.next (<anonymous>)
My code is as follows:
async onChange( newValue: string | null) {
const vm = this.serviceProvider.get<CanvasWorksheetVM>(CanvasWorksheetVM.serviceProviderName);
const context = this.serviceProvider.get<ControlContextService>(ControlContextService.serviceProviderName);
const id = this.record.getRecordId();
const jsonObj: { id: string, textValue?: string | null, numberValue?: number | null } = { id: this.id };
let numValue : number | null = null;
const record = context.getDataset().records[id]
switch(this.fxnlDataType){
case "string":
jsonObj.textValue = newValue ? newValue as string : null
this.textValue = newValue ? newValue as string : null
try {
//@ts-ignore
await record.setValue("TextValue", newValue).then(()=>console.log({dirty :
record.isDirty()}));
} catch(e){
console.error(e as Error);
}
break;
}
try {
//@ts-ignore
await record.save()
} catch(e){
console.error(e as Error)
}
vm.sampleProperty = JSON.stringify(jsonObj);
}
After having done some testing the issue really is that I was passing the dataset a customized collection from my canvas app. The record.save() is trying to save the changes to the database hence it could not. I think, as @DianaBirkelbach has mentioned elsewhere, I will need to use an output property and the on change event from my canvas app to update the record manually.
Thank you Diana, I should have mentioned that the datasource is actually a customized collection that I passed from the canvas app. Perhaps save() doesn't have a concept of how to update to a collection. However, I am going to try it on a custom page which is my final destination in any case.
Hi @KASCHN ,
Haven't done it inside a Canvas App, but I did it inside a CustomPage bound to something else that Dataverse.
It could be a Canvas App issue. But maybe it depends on the Datasource type you are using.
The Dataset inside the Canvas Apps PCFs have a method "getDataSetCapabilities", where you can check if your datasource "isEditable", "isSortable", "canCreateNewRecords" and so on: https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/dataset/getdatasetcapabilities?WT.mc_id=BA-MVP-5004107
Maybe it helps to get closer to the reason behind the error message...?
WarrenBelz
85
Most Valuable Professional
mmbr1606
55
Super User 2025 Season 1
Michael E. Gernaey
52
Super User 2025 Season 1