Hi, Need assistance using SDK.Rest. retrieveRecord trying to add the primary contact from the Account form to the Lead form when the existing customer type is account .They do not want existing customer leads put in as opportunities right away as there is a high percentage of "maybe i will buy", so Out of box CRM process does not work. Don't want to use a calculated field to map from account in order to allow primary contact ability to be changed in the lead entity.
I have added SDK.REST.js to the form library. Receiving "Error 404 Resource not found for the segment "accountset".
I have checked the GUID ID that is passed to the SDK.REST.retrieveRecord and it matches the account guid.
Here is the code:
function UpdateLeadInfo(){
var customer=Xrm.Page.getAttribute("customerid").getValue()[0].id;
var accountname=Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
if(customer != null){
var custype=Xrm.Page.getAttribute("customerid").getValue()[0].entityType;
if(custype=="contact"){
var ContactName=Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
var mysplit=ContactName.split(" ");
var fname=mysplit[0];
var lname=mysplit[1];
Xrm.Page.data.entity.attributes.get("firstname").setValue(fname);
Xrm.Page.data.entity.attributes.get("lastname").setValue(lname);
} else if (custype == "account") {
var accountname = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
alert("name is" + accountname);
var customera = Xrm.Page.getAttribute("customerid").getValue()[0].id;
alert("id is" + customera);
Xrm.Page.data.entity.attributes.get("companyname").setValue(accountname);
var columns = "name, primarycontactid";
SDK.REST.retrieveRecord(customera, "account", columns, null,
function (result) {
UpdatePcontact(result);
}, function (error) {
alert(error.message);
}
);
}
}
}
function UpdatePcontact(result){
var pcontact=result.primarycontactid;
if(null !=pcontact){
Xrm.Page.getAttribute("newbtss_primarycontact").setValue([{ id: pcontact.Id, name: pcontact.Name, entityType: pcontact.LogicalName }]);
}
}
*This post is locked for comments