Hey, I want to set the field Region (lookup on new entity) – filtered by Country. if emptied, then empty city
- Entity Region (has a name field + a lookup on country)
City (lookup on new entity) – filtered by region
Country code à fetched from country automatically
- Entity: Country (has a name field + area code integer & mandatory field that only allows 5 characters (ex 00961)
- Entity Region (has a name field + a lookup on country)
- Entity City (has a name field and a lookup on country and region)
i'm using the following script but its wrong any help?
function FilterLookup()
{
Xrm.Page.getControl("new_region").addPreSearch(function () {
var region= Xrm.Page.getAttribute("new_region").getValue();
// Get the lookup Object, and extract the value of region
if(region != null)
{
var region = region[0].name;
var city = region[0].text;
// Filter the cities by region
fetchXml = "";
// Apply the filter to the field
Xrm.Page.getControl("new_city").addCustomFilter(fetchXml);
}
});
}
*This post is locked for comments
Hi please try these.
You can refer to this http://www.inogic.com/blog/2015/08/apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script/ blog in which we have detailed functioning explained for how filtering is applied with code example. You can check out if you are missing anything.
Thanks!
Hi,
What happens when your script runs? It looks like this part is wrong:
fetchXml = "";
Xrm.Page.getControl("new_city").addCustomFilter(fetchXml);
because you aren't adding any criteria to the xml, just an empty string. You'll need to add in the actual condition like it's documented here: msdn.microsoft.com/.../gg334266.aspx
Hope this helps! I'd appreciate if you'd mark this as Answering your question.
Thanks,
Aiden
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156