Hi Guys,
Thank you for your help so far.
I wrote this following code to retrieve Quote entity data and create a "Service Agreement" custom entity record.
It works fine but now I need to Retrieve Opportunity lookup field and while creating the new service agreement record I need to fill the opportunity field there.
I have commented out this
entity["bin_opportunity@odata.bind"] = "/opportunities(lookupValue[0].id)";
as it gives me following error
')' or ',' expected at position 12 in '(lookupValue[0].id)'.
I tried with ( ) but no luck. Do you guys have any suggestions?
Entire code
function CreateServiceAgreement() {
debugger;
//Retrive Quote data
var QuoteID = Xrm.Page.data.entity.getId();
Xrm.WebApi.online.retrieveRecord("quote", QuoteID, "?$select=_accountid_value,name,_opportunityid_value").then(
function success(result) {
debugger;
var _accountid_value = result["_accountid_value"];
var _accountid_value_formatted = result["_accountid_value@OData.Community.Display.V1.FormattedValue"];
var _accountid_value_lookuplogicalname = result["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
var name = result["name"];
alert(name);
var _opportunityid_value = result["_opportunityid_value"];
var _opportunityid_value_formatted = result["_opportunityid_value@OData.Community.Display.V1.FormattedValue"];
var _opportunityid_value_lookuplogicalname = result["_opportunityid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
//create Service Agreement
var entity = {};
entity.bin_name = name;
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = _opportunityid_value; // GUID of the lookup id
lookupValue[0].name = _opportunityid_value_formatted; // Name of the lookup
lookupValue[0].entityType = _opportunityid_value_lookuplogicalname; //Entity Type of the lookup entity
alert(lookupValue[0].id);
//entity["bin_opportunity@odata.bind"] = "/opportunities(lookupValue[0].id)";
Xrm.WebApi.online.createRecord("bin_serviceagreement", entity).then(
function success(result) {
var newEntityId = result.id;
//below code is used to open the created record
var windowOptions = {
openInNewWindow: true
};
//check if XRM.Utility is not null
if (Xrm.Utility != null) {
//open the entity record
Xrm.Utility.openEntityForm("bin_serviceagreement", newEntityId, null, windowOptions);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}