function setComponentDetails(executionContext) {
var formContext = executionContext.getFormContext();
var lookupValue = formContext.getAttribute("collab_component").getValue();
if (lookupValue != null && lookupValue.length > 0) {
var componentId = lookupValue[0].id.replace("{", "").replace("}", "");
var entityName = lookupValue[0].entityType;
// Retrieve the lookup record fields using Web API
Xrm.WebApi.retrieveRecord(entityName, componentId, "?$select=collab_name,collab_number,collab_averageprice").then(
function success(result) {
// Always set collab_componentpartname
formContext.getAttribute("collab_componentpartname").setValue(result.collab_name);
// Always set collab_componentpartnumber
formContext.getAttribute("collab_componentpartnumber").setValue(result.collab_number);
// Always set collab_componentavgprice
formContext.getAttribute("collab_componentavgprice").setValue(result.collab_averageprice);
},
function(error) {
console.error("Error retrieving component details: " + error.message);
}
);
} else {
// If lookup is cleared, clear the dependent fields as well
formContext.getAttribute("collab_componentpartname").setValue(null);
formContext.getAttribute("collab_componentpartnumber").setValue(null);
formContext.getAttribute("collab_componentavgprice").setValue(null);
}
}
Will this code need to be changed to conform with JQuery? And in terms of running the code, is not not enough to have the JS running onsave of the form? Do I need to add it to the "Custom JavaScript" section in Additional Settings of the Basic Form?
I'm very new to this so just trying to figure it out as I go.
Thanks