Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

CRM 2015 - retrieve data from related entity

$
0
0

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.


Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>