cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KASCHN
Advocate I
Advocate I

Dataset PCF for Canvas App - error on record.save()

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);
    }

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
KASCHN
Advocate I
Advocate I

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. 

View solution in original post

3 REPLIES 3
DianaBirkelbach
Super User
Super User

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/getdatase...

Maybe it helps to get closer to the reason behind the error message...?

 

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

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. 

KASCHN
Advocate I
Advocate I

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. 

Helpful resources

Announcements
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 (4,609)