cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SaWu
Impactful Individual
Impactful Individual

Problem with Patch and createdby

Hello

Please be so kind as to read my full post before responding.
Thank you for your consideration.

I am trying to make the PowerApp for CDS that I am working on capable of being used offline.
Hence, I usually collect local copies from my Data Sources, add some custom PowerApps columns for things like thumbnails or temporary results.
Before syncinc back to CDS using Patch (inside ForAll or AddColumns (to get proper GUIDs back)) I would drop the additional custom offline columns.

I just started getting a weird nondescript error with my Sync Button containing Patch/ForAll.
PowerApps 3.19061.14, DataBase Version 9.1.0.5426
Upon a Sync attempt I got the nondescript "Value mus be a data entity record error".
image.png
I did some tests and first found that just using patch with something simple like

ClearCollect(TmpPatched, AddColumns(LocalToSubmit, "real_id", Patch([@'PowerFair-Leads'],
    {
        kk_messeapp_leadid: If(submitted, kk_messeapp_leadid, Blank())
    },
    {
        kk_notes: "Test"
    }
).kk_messeapp_leadid));

worked, but didn't with "full entities" from forms or galleries etc.
With some systematic trial and error using ShowColumns/DropColumns going through all the fields in my entity, I could narrow down my problem to the "createdby" column.
Dropping this column (in addition to my custom offline non-CDS columns) seems to alleviate this problem.
So my current code looks like this:
image.png
Did something change with "createdby"?
It's easily possible I missed an annoucement or something, maybe related to new CDS features etc.
Or is this just some kind of "freak accident"?

Thank you,
    Sa Wu.

2 REPLIES 2
v-yutliu-msft
Community Support
Community Support

Hi @SaWu ,

I've made a smilar test but not met the same problem like your description.

As far as I know, created by is a read-only look-up field in CDS.

It's automatically genereted by system.

You could only display it in PowerApps.

It's not supported to update the field inside the app.

So, maybe your issue is a "freak accident".

Could you show me more settings about created by field?

 

Best regards,

Community Support Team _ Phoebe Liu

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
SaWu
Impactful Individual
Impactful Individual

Hello @v-yutliu-msft 

 

Thank you for your response.
My error only shows up when updating (actually patching) an exisiting element, not with new record submissions.
My guess is that CDS/Dynamics doesn't like me patching with full records from local collections because of my offline considerations instead of using SubmitForm/Form.Updates, which, as far as I understand, don't modify columns like createdby or modifiedon.

As for my actual "code"/formulas, please find the signifcant/abridged parts of it here:

Download:

Refresh('PowerFair-Leads');
ClearCollect(LocalLeads, Filter('PowerFair-Leads', createdby.systemuserid=userId, statuscode=leadStatusActive));
ClearCollect(LocalExhibitionLeads, AddColumns(LocalLeads,
    "new_front", false,
    "new_extra", false,
    "submitted", true,
    "new_thumbnails", []
));
If(!isBrowser, SaveData(LocalExhibitionLeads, "LocalExhibitionLeads"))

Save:

If(!newLead,
    RemoveIf(LocalExhibitionLeads, kk_messeapp_leadid = oldId)
);
RemoveIf(LocalToSubmit, kk_messeapp_leadid = oldId);
ClearCollect(NewTmp, selectedItem);
UpdateContext({newItem: Patch(
    {},
    First(NewTmp),
    If(newLead,
    {
        kk_messeapp_leadid: GUID(),
        submitted: false
    }, {}),
    {
        kk_address1_city: Left(InputFieldsEditAddress1City.Text, fieldLimit),
        kk_address1_country: Left(InputFieldsEditAddress1Country.Text, fieldLimit),
        kk_address1_line1: Left(InputFieldsEditAddress1Line1.Text, fieldLimit),
        kk_address1_postalcode: Left(InputFieldsEditAddress1PostalCode.Text, fieldLimit),
        kk_address1_stateorprovince: Left(InputFieldsEditAddress1StateOrProvince.Text, fieldLimit),
        kk_name1_firstname: Left(InputFieldsEditName1FirstName.Text, fieldLimit),
        kk_name1_lastname: Left(InputFieldsEditName1LastName.Text, fieldLimit)
    }
)});
UpdateContext({
    selectedItem: newItem,
    newLead: false
});
Collect(LocalExhibitionLeads, selectedItem);
Collect(LocalToSubmit, selectedItem);
If(!isBrowser,
    SaveData(LocalExhibitionLeads, "LocalExhibitionLeads");
    SaveData(LocalToSubmit, "LocalToSubmit")
)

Upload:

ClearCollect(TmpSubmit, DropColumns(LocalToSubmit, "new_front", "new_extra", "submitted", "new_thumbnails", "createdby", "modifiedon"));
ClearCollect(TmpPatched, AddColumns(LocalToSubmit, "real_id", Patch([@'PowerFair-Leads'],
    {
        kk_messeapp_leadid: If(submitted, kk_messeapp_leadid, Blank())
    },
    Patch({},
        LookUp(TmpSubmit, TmpSubmit[@kk_messeapp_leadid] = LocalToSubmit[@kk_messeapp_leadid]),
        {
            kk_messeapp_leadid: If(submitted, kk_messeapp_leadid, Blank())
        }
    )
).kk_messeapp_leadid));
ForAll(TmpPatched, Patch(LocalExhibitionLeads, 
    {
        kk_messeapp_leadid: kk_messeapp_leadid
    },
    {
        kk_messeapp_leadid: real_id,
        submitted: true
    }
));
Concurrent(
    Clear(LocalToSubmit);
    If(!isBrowser, SaveData(LocalToSubmit, "LocalToSubmit")),
    If(!isBrowser, SaveData(LocalExhibitionLeads, "LocalExhibitionLeads"))
)


Thank you,
    Sa Wu.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (901)