We have a need in our process to pass information from three fields in the Opportunity record to the Opportunity Close form. Two of these fields are Lookup fields to other custom entities while one is an option set. This information was to passed through JavaScript but I am having issues pulling the text from the lookup fields and so must have something wrong. (I'm a bit new to JavaScript). I'm hoping someone might be able to help with this coding or perhaps there is a better way to pass this information over. Below is a sample of the JavaScript. Thanks.
function getRelatedInfo(e) {
// Get the Form Context
var formContext = e.getFormContext();
// Set variables for the related entity to get data from
try{var recordGuid = formContext.getAttribute("opportunityid").getValue()[0].id; }
catch(err) {}
// If the recordGuid contains data
if (recordGuid != null) {
// Use the WebApi to get data
Xrm.WebApi.retrieveRecord("opportunity", recordGuid, "?$select=z2t_optype&$expand=z2t_Division($select=z2t_name),z2t_Make($select=z2t_name)").then(
// If successful, set variables for the results
function success(result) {
var OpType = result.z2t_optype;
if (result.hasOwnProperty("z2t_Division") && result["z2t_Division"] !== null) {
var Division = result["z2t_Division"]["z2t_name"]; // Text
}
if (result.hasOwnProperty("z2t_Make") && result["z2t_Make"] !== null) {
var Make = result["z2t_Make"]["z2t_name"]; // Text
};
// Set the form fields
formContext.getAttribute("gp_opportunitytype").setValue(OpType);
formContext.getAttribute("gp_Division").setValue(z2t_Division_z2t_name);
formContext.getAttribute("gp_Make").setValue(z2t_Make_z2t_name);
},