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?
Hi @MrNappa ,
That's a little strage...
Did you make other changes about variable reg?
Could you tell me Registrations table and RefItems table's structure?
I've made a test and found that the two ways to create variable will result the same data.
Here's my test:
UpdateContext({ reg: { vdt_name: "test", vdt_date: Now() } }); UpdateContext({ reg: Patch( reg, { vdt_refitem: {id:"aa"} } ) });
UpdateContext({ reg1: { vdt_name: "test", vdt_date: Now(), vdt_refitem: {id:"aa"} } });
And the result:
Best regards,
Hi Phoebe,
The field is a simple Lookup field to another table.
Also -- after some further testing, I it might have something to do with async behavior of the patch command?
If you look at the following test:
You can see that only the 2nd patch is 'problematic'. If I include the lookup field in the original UpdateContext, or if I Patch it with a cached value, the final patch seem to work correctly.
Update: Actually, when I comment out the 2nd patch line, the third patch also gives an error. So that was a false positive.
User | Count |
---|---|
26 | |
20 | |
7 | |
6 | |
4 |
User | Count |
---|---|
37 | |
26 | |
18 | |
9 | |
8 |