Hi Jane,
This is not working because customerid field is of type customer which can accept account or contact record. So while setting the id, you also need to set the type of record.
try this code
==============
if (Xrm.Page.data.entity.attributes.get("customerid").getValue() != null) {
parameters["customerid"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].id;
parameters["customeridname"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
parameters["customeridtype"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].entityType;
}
===============
Complete code:
==================
function bill() {
var parameters = {};
var OpportunityId = Xrm.Page.data.entity.getId();
var OpportunityName = Xrm.Page.data.entity.attributes.get("name").getValue();
parameters["opportunityid"] = OpportunityId;
parameters["opportunityidname"] = OpportunityName;
if (Xrm.Page.data.entity.attributes.get("customerid").getValue() != null) {
parameters["customerid"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].id;
parameters["customeridname"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
parameters["customeridtype"] = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].entityType;
}
var windowOptions = {
openInNewWindow: true
};
Xrm.Utility.openEntityForm("invoice", null, parameters, windowOptions);
}
===========================
I hope this helps. If my post answers your question, please mark as "Verified"