web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filter lookup based on business Unit

(0) ShareShare
ReportReport
Posted on by 815

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

*This post is locked for comments

I have the same question (0)
  • Inogic Profile Picture
    703 on at

    We have done the same functionality by creating three custom entities “Market Segment, Product and Region” with fields, Name and Business Unit in each. 

    And we are not facing any issues in filtering lookup fields, you just need to add filtering functions on load of form and everything will work fine.

    If this answered your question, please make sure to Mark this as an Answer.

    Thanks!

  • Syed_Faisal Profile Picture
    815 on at

    Hi,

    Did you create separate JS file  for the three custom entities or just created 1 JS file and entered all the three custom entities function ?

  • Syed_Faisal Profile Picture
    815 on at

    Hi,

    I tried with 3 custom entities but lookup function working only on 3rd lookup, I disable function of last entity then the function working on 2nd lookup.

    What here i analyse is, when adding multiple lookup function, formula working only on last lookup.

    Please help !

  • Verified answer
    Syed_Faisal Profile Picture
    815 on at

    Hi,

    I removed all the javascript function and manually changes lookup field filtering to business unit, it filter according to business unit and works. Thanks !

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans