Hi all,
I'd like to know if is possible to limit the values that come from a lookup field, depending on the values that come from an optionset field I have in the same form.
thank you in advance.
*This post is locked for comments
Hi all,
I'd like to know if is possible to limit the values that come from a lookup field, depending on the values that come from an optionset field I have in the same form.
thank you in advance.
*This post is locked for comments
Fedor, lots of thanks, that could really help me, I'll post down my code here, for it may help someone in the future:
function preFilterLookup() {
Xrm.Page.getControl("new_fasedopipelineid").addPreSearch(function () {
addLookupFilter();
});
}
function addLookupFilter() {
var tipoOportunidade = Xrm.Page.getAttribute("new_tipodeoportunidade").getText();
if (tipoOportunidade == "Run Rate") {
Xrm.Page.ui.controls.get("new_subfasedopipelineid").setVisible(false);
fetchXml = "<filter type='and'><condition attribute='statuscode' operator='eq' value='100000000' /></filter>";
Xrm.Page.getControl("new_fasedopipelineid").addCustomFilter(fetchXml);
}
else{
Xrm.Page.ui.controls.get("new_subfasedopipelineid").setVisible(true);
fetchXml = "<filter type='and'><condition attribute='statuscode' operator='ne' value='2' /></filter>";
Xrm.Page.getControl("new_fasedopipelineid").addCustomFilter(fetchXml);
}
}
I used the statuscode field in the lookup I wanted to filter, so I was able in the "if" to bring what I wanted to filter, and in the "else" everything = ).
Hi Kyle,
That's awesome information - I'm definitely bookmarking this post. Thanks!
Aiden
Hi JoaoL,
You can make your option set field global and add it on entity which you want to filter. And then use addCustomFilter() method to add a filter to this lookup.
Something like this. It's the best supported solution, i think.
You can use the methods support by the Lookup control type to filter the lookup field with your own fetchXML filter. Try the addCustomFilter() method, passing your optionset value as the criteria for a fetchXML filter. Note that you have to use the addCustomFilter() method in conjunction with the addPreSearch() method, as explained in the SDK.
= ,(
sad world.
that's ok, thanks for the help ^^.
Joaol,
My apologies, I misread your question and thought you wanted to do it in a grid. You may be able to take the same approach since the lookup uses a view but I haven't tried that.
There is an option for Related Record Filtering but that only works for other entities. Unfortunately I don't think there's a way to do it.
Aiden
Hi JoaoL,
You can do this, but it's not strictly supported. You can dynamically set the FetchXml of your grid, so as long as you can build a query based on the option chosen, you could do it.
Here's a good blog post about how to set FetchXml on your grid:
joshimandarblog.wordpress.com/.../crm-2015-applying-custom-fetchxml-to-a-subgrid-using-javascript
You'd want to run javascript OnLoad of your form and OnChange of the option set, which will build the FetchXml query and set it on the grid.
If this helps I'd really appreciate if you would mark this as a Verified answer.
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,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156