I am quite new to javascript and got a question which is probably simple to many :-)
I got a Javascript on Incidents where I retrieve a value from related entiy new_Agreement.
The lookupfield new_Agreement is set by the "mapping function" and therefore I want to run the Javascript on load.
So the value in new_reference from Agreement is set in to similar field on the Incident record.
However, the user should be able to overwrite the new value, so therefore I only want to run the js function if the new_reference on Incident is null. How do I add this condition to the javascript ?
function RetrieveReference (executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("new_agreement").getValue()) {
var id = formContext.getAttribute("new_agreement").getValue()[0].id;
Xrm.WebApi.retrieveRecord("new_agreement", id, "?$select=new_reference").then(
function success(result) {
formContext.getAttribute("new_reference").setValue(result.new_reference);
},
function (error) {
console.log(error.message);
});
}
}
Best Regards,
Dorthe