I got this error message when trying to create a new record that contained a lookup field. When investigating it further, I found the following.
My code was set up like:
// Create item
UpdateContext({
reg: {
vdt_name: "test",
vdt_date: Now()
}
});
// [..] some other code
// add reference to item
UpdateContext({
reg: Patch( reg, { vdt_refitem: LookUp( RefItems, RefItem=selected.RefItemId ) } )
});
// save the item
Patch( Registrations, Defaults( Registrations ), reg );
This gave me an error "Value must be an entity record" on the final patch to the data source.
However, when I changed it to the following:
// Create item
UpdateContext({
reg: {
vdt_name: "test",
vdt_date: Now(),
// include the reference now
vdt_refitem: LookUp( RefItems, RefItem=selected.RefItemId )
}
});
// [..] some other code
// save the item
Patch( Registrations, Defaults( Registrations ), reg );This code runs and works correctly.
I inspected the contents of the variable in both scenarios, and they both seem to contain all fields that I specified, including the lookup value. The only difference is that in the first instance, the lookup field reference is added later by doing a patch. What makes this not work?