Hi -
CRM 2016 on-prem.
I have two custom entities, one called Meeting Product and one called Meeting.
I have a field on Meeting which is a lookup to the Meeting Product entity. The Meeting Product record contains a field called Total Cost (afc_totalcost). The Meeting record contains a field called Price Per Unit (afc_priceperunit).
When the user selects a Meeting Product using the lookup field on the Meeting record, I want to have a piece of JavaScript, which retrieves the value Total Cost field on the Meeting Product record and inserts it into the Price Per Unit field on the Meeting record.
I know this will be an onChange event on the lookup field. Can anyone help please??
This is the JS I have, but I get an error when testing:
function RetrieveProduct() {
var lookupObject = Xrm.Page.getAttribute("afc_meetingproduct");
if (lookupObject != null) {
var lookUpObjectValue = lookupObject.getValue();
if ((lookUpObjectValue != null)) {
var lookupid = lookUpObjectValue[0].id;
}
}
var id = lookupid;
retrieveRecord(id, "afc_meetingproduct", retrieveProductPrice, null);
}
function retrieveProductPrice(data, textStatus, XmlHttpRequest) {
var meetingproduct = data;
if (meetingproduct.afc_totalcost != null) {
Xrm.Page.getAttribute("afc_priceperunit").setValue(meetingproduct.afc_totalcost);
}
else {
Xrm.Page.getAttribute("afc_priceperunit").setValue(null);
}
}
Thank you.