Hi,
I am getting error on page when I add below code. Kindly help me to find the error. How to find the error. But the script is working.
Please find the script and screen. I added this script to get option set text which marked in bold letters.
will this scripts make any issue when upgrade CRM 2011 to CRM 2013 to CRM 2015
function productid_onchange()
{
if (Xrm.Page.getAttribute("productid").getValue() != null )
{
var itemid = Xrm.Page.getAttribute("productid").getValue()[0].id;
var context = Xrm.Page.context;
serverUrl = context.getServerUrl();
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveResult = new XMLHttpRequest();
retrieveResult.open("GET", ODataPath + "/ProductSet?$select=ProductTypeCode,New_PresalesTeam&$filter=ProductId eq guid'" + itemid + "'", false);
retrieveResult.setRequestHeader("Accept", "application/json");
retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveResult.send();
alert(retrieveResult.readyState);
alert(retrieveResult.status);
if (retrieveResult.readyState == 4 )
{
alert("2");
if (retrieveResult.status == 200)
{
alert("3");
var retrieved = JSON.parse(retrieveResult.responseText).d;
Xrm.Page.getAttribute("new_categorytype").setValue(retrieved.results[0].ProductTypeCode.Text);
Xrm.Page.getAttribute("new_presalesteam").setValue(retrieved.results[0].New_PresalesTeam.Text);
var ptype =retrieved.results[0].ProductTypeCode.Value;
var pteam = retrieved.results[0].New_PresalesTeam.Value;
}
}
}
SDK.Metadata.RetrieveAttribute("product", "new_presalesteam", null, true, function (result) {
for (var i = 0; i < result.OptionSet.Options.length; i++) {
if (result.OptionSet.Options[i].Value == pteam)
{ var text = result.OptionSet.Options[i].Label.LocalizedLabels[0].Label;
alert(text);
var value = result.OptionSet.Options[i].Value;
alert(value);
}
}
},
function (error) {
alert("error");
}
);
if (Xrm.Page.getAttribute("uomid").getValue() == null)
{
var lookupData = new Array();
var lookupItem= new Object();
lookupItem.id = '{40AE01DD-385B-43E0-8698-00D1E9462CCF}';
lookupItem.typename = 'Unit';
lookupItem.name = 'EACH';
lookupData[0] = lookupItem;
Xrm.Page.getAttribute("uomid").setValue(lookupData);
Xrm.Page.getAttribute("uomid").setSubmitMode("always");
}
}