Hi,
I have my work order entity. On this i have the service account lookup field realted to account. On the account record i have a parent account field.
Also i have created a new field called "x_parentaccount" on my work order. I wan't the parent account from the selected service account to be populated into my new field x_parentaccount. I cannot get this to work?
// GET Lookup function retrieveParentAccount(executionContext) { // Access the field on the form var field = executionContext.getFormContext().getAttribute("msdyn_serviceaccount"); // Verify it does exist on the form if (field != null) { // Get its field value; Returns the Lookup object var value = field.getValue(); // To get the Id, Name and Entity Name (account/contact) var record_id = field.getValue()[0].id; var record_name = field.getValue()[0].name; var record_entityName = field.getValue()[0].entityType; record_id=record_id.replace('{','').replace('}',''); GetRelatedData(executionContext,record_id); } } function GetRelatedData(executionContext,record_id) { var formContext = executionContext.getFormContext(); // Xrm.WebApi.retrieveRecord("account", record_id, "?$select=parentaccountid").then( function success(result) { if (result.parentaccountid == true) formContext.getAttribute(x_parentaccount).setValue(true); }, function error(error) { Xrm.Navigation.openAlertDialog({ text: error.message }); } ); }
Another more simpl script was this - but cannot get this to work either...
function retrieveParentaccount(executionContext) { var formContext = executionContext.getFormContext(); // Access the field on the form var fieldValue = formContext.getAttribute("msdyn_serviceaccount").getValue(); // Verify it does exist on the form if (fieldValue != null) { // To get the Id, Name and Entity Name (account/contact) var record_id = fieldValue[0].id; Xrm.WebApi.retrieveRecord("account", record_id, "?$select=parentaccountid").then( function success(result) { if (result.parentaccountid == true) { formContext.getAttribute("x_parentaccount").setValue(true); } }, function error(error) { Xrm.Navigation.openAlertDialog({ text: error.message }); } ); } }