Hi,
Can anyone help me regarding, how to filter optionset values using lookup.
Ex: If lookupText is A optionsetvales x,y,z
if lookupText is B opetionsetvalues a,b,c
*This post is locked for comments
Hi,
Can anyone help me regarding, how to filter optionset values using lookup.
Ex: If lookupText is A optionsetvales x,y,z
if lookupText is B opetionsetvalues a,b,c
*This post is locked for comments
Hi,
I also got the same requirement in which I need to filter based upon lookup entity value so first I am rederiving stage value from the lookup entity and then setting in the lookup and below code is working fine for me:
selectedStage = result["mcshhs_stage"];
selectedStageValue = result["mcshhs_stage@OData.Community.Display.V1.FormattedValue"];
var optionset = context.ui.controls.getByName("mcshhs_stage");
var optionsetValues = optionset.getOptions();
optionset.clearOptions();
if (selectedStage != undefined && selectedStage != null && selectedStage != '') {
var stageArr = selectedStage.split(',');
var stagevalueArr = selectedStageValue.split(';');
for (var i = 0; i < stageArr.length; i++) {
var option = { text: stagevalueArr[i], value: stageArr[i] };
optionset.addOption(option);
}
Hi
Normally to achieve what you want in a well-supported way, is to use two entities and have two lookups on the form and filter them based on the selection of the A.
However, due to increasing demand for Cascaded OptionSets, there is in a way a kind of supported and recommended solution that you could use it in any entity form.
Please have a look at these links
[View:https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg594433(v=crm.8):750:50]
[View:https://code.msdn.microsoft.com/create-dependent-844db2d1:750:50]
Hope this helps
Hi Miss Dynamics,
How did you go with this? If you have got your answer, please close the thread by marking the helpful suggestion.
Marking the suggestion as Verified helped other facing the same/similar issue. Appreciate if you can close your previous threads as well.
Hi,
If possible change your second field to Lookup (create new one). so that it would be OOB feature to filter value with in. see the link for quick help - community.dynamics.com/.../how-to-filter-lookups-by-related-records-in-dynamics-365
Hi ,
Try with this -
function OptionSetAddRemoveBasedOnLookup() { var lookupItem = Xrm.Page.getAttribute("new_ContactLKUP").getValue(); // Replace lookup field Name if (lookupItem != null) { contactId = lookupItem[0].id; contactName =lookupItem[0].name; var optionSet = Xrm.Page.ui.controls.get("new_myoptionset"); var optionSetValues = optionSet.getAttribute().getOptions(); // retrieve All options of Option set field optionSet.clearOptions(); optionSetValues.forEach(function (element) { if(contactName == "Some Name") { if (element.value == "831260009") // Add Options which you want to show based on value , you can also check with Optionset text like element.text optionSet.addOption(element); if (element.value == "831260008") // Remove options which you want to hide based on value optionSet.removeOption(element); } else if (contactName == "Diff Name") { // You can also do for different lookup name } }); } }
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