Hello,
I am facing the following problem:
There are two fields on a form of our system. The first is a lookup to an entity, the second is a date field. The lookup is on the entity "invoice" and this also has a date field on the form.
I would like to implement the functionality that when the first field (logical name: "invoiceid") is updated, the second field is filled with the value that is in the date field of the "invoice" entity. The date field has the logical name "invoicedate" on both forms.
I wrote the following code:
function Invoiceid_OnChange(executionContext) { let formContext = executionContext.getFormContext(); let invoiceNumber = formContext.getAttribute("invoiceid").getValue(); var invoiceNumberEntityType = invoiceNumber[0].entityType; var invoiceNumberId = invoiceNumber[0].id; Xrm.WebApi.retrieveRecord(invoiceNumberEntityType, invoiceNumberId.replace('{', '').replace('}', ''), "?$select=invoicedate").then( function success(result) { formContext.getAttribute("invoicedate").setValue(result[invoicedate]); }, function (error) { console.error(error.message); } ); }
The variables "invoiceNumberEntityType" and "invoiceNumberId" contain the correct values, I have already checked this.
Unfortunately, when I deploy the script, I get the following error: "TypeError: Cannot read properties of undefined (reading 'retrieveRecord') at Invoiceid_OnChange". I have checked "Pass execution context as first parameter" in the handler properties.
I am thankful for any advice.