Quantcast
Channel: Sam's Activities
Viewing all articles
Browse latest Browse all 3363

Filter lookup based on business Unit

$
0
0

Hi,

Let me brief first current scenario. We have customize lead entity by using Ribbon Workbench. When user click on new lead, a HTML window will come and ask to select Business Unit. Once user selected Business Unit . This below formula added on form properties.

*********************************************************************************************************************

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");

}
}

****************************************************************************************************************************

Above formula works fine.

We have created 3 custom entity (Market Segment, Product, Region) Each entity has 2 field (Name & Business Unit)

Issue happening here when we running multiple lookup filters, sometime it works properly some it doesn't.

Requirement : Once business unit selected, all the 3 custom entity should show only name related to business unit.

Please help !

Regards

Faisal


Viewing all articles
Browse latest Browse all 3363

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>