Hi Mahender,
Webresource created and it work fine inside network, outside (External) network it is not working, pl help.
Here is the code :
function SetBUField() {
var BUName = window.parent.Xrm.Page.getAttribute("new_bu").getValue();
if (BUName != null) {
var req = new XMLHttpRequest();
req.open("GET",
Xrm.Page.context.getClientUrl() + "/api/data/v8.0/businessunits?$select=businessunitid,name",
false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var businessunitid = results.value[i]["businessunitid"];
var name = results.value[i]["name"];
if (name == BUName) {
var lookUpValue = new Array();
lookUpValue[0] = new Object();
lookUpValue[0].id = businessunitid.replace('{', "").replace('}', "").toString();
lookUpValue[0].name = name.toString();
lookUpValue[0].entityType = "businessunit";
Xrm.Page.getAttribute("new_businessunitid").setValue(lookUpValue);
}
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
}
//Function to Filter Market Segment
MarketSegmentFilterSearch = function () {
Xrm.Page.getControl("new_marketsegmentid").addPreSearch(function () {
AddPreSearch();
});
}
//Function to Filter Market Segment
AddPreSearch = function () {
var businessUnitId = Xrm.Page.getAttribute("new_businessunitid").getValue()[0].id;
if(businessUnitId != null){
var Filter = "<filter type='and'><condition attribute='new_businessunitid' operator='eq' uitype='businessunit' value='"+businessUnitId+"'/></filter>";
Xrm.Page.getControl("new_marketsegmentid").addCustomFilter(Filter, "new_marketsegment");
}
}