Any DV/CDS entity that has Notes enabled will fail to create records using a data set from a collection with the error {Attachments}: Field 'Id' is required. If Notes are not enabled, it works. If someone (e.g. customer) enables Notes on the entity you are using, after your Canvas app is installed, your app is now broken.
The only way to create records is to write a Patch command that specifies EVERY field you want. Doing that way makes the process painfully slow to create new records. It takes just under 30 PAINFUL minutes to create 300 individual records across six entities in a Canvas App.
Here is the sample code using the Account entity. I am trying to copy an existing record, change the account name and then create a new account record.
//get an account record(s)
ClearCollect(account_col, Filter(Accounts, name = "Adventure Works (sample)") );
//Remove server generated data fields to prevent server errors
//RANT: Why doesn't the server just ignore fields it is creating data for and just show a warning instead of failure?
ClearCollect(accountafterdrop_col, DropColumns(account_col,
"accountid",
"merged",
"opendeals",
"opendeals_date",
"opendeals_state",
"openrevenue_date",
"openrevenue",
"openrevenue_base",
"openrevenue_state",
"revenue_base",
"address1_composite",
"exchangerate",
"_ownerid_value",
"createdby",
"createdon",
"createdonbehalfby",
"importsequencenumber",
"modifiedby",
"modifiedon",
"modifiedonbehalfby",
"overriddencreatedon",
"owningbusinessunit",
"owningteam",
"owninguser",
"statecode",
"statuscode",
"timezoneruleversionnumber",
"utcconversiontimezonecode",
"versionnumber"
)
);
// rename/update account record(s) to be copied/created
UpdateIf(accountafterdrop_col, true, { name: "Test Account Created From Patch" } )
// create new account record(s)
ForAll(accountafterdrop_col As NewAccount,
Patch(Accounts, Defaults(Accounts) , NewAccount)
);
Patch Create Fail Error: {Attachments}: Field 'Id' is required.
Also tried: Patch(Accounts, accountafterdrop_col);
It fails with the same error too.
What modification is required to the collection "accountafterdrop_col" to make the Patch statements above work? Or any other ideas to fix this issue?
Thanks,
-Art
(Also posted this to ISV forum)