Hi:
I have a lookup field on a web/entity form that I have rendered as a dropdown using Metadata. I need to hide specific option set values on the portal.
I tried to do so using Javascript, though I am new! Here is an example of something I have tried:
$(document).ready(function(){
$("abc_fieldname").val("45cd908-89e5-70fd-003034a4bb6").hide();
});
Though this is hiding the whole dropdown, not the specific option set value. Can someone help me with this?
Thanks,
Luke
*This post is locked for comments
Hello Luke O,
I have the same problem. How did you get it fixed?
Thank you very much!
Hi Luke,
This is possible but complex. You'll have to inspect the DOM carefully and use JQuery to manipulate the list items.
In a recent project, I had a SubGrid which had the Create Action. This opens a modal window which shows an Entity Form. In this Entity Form, I had a lookup. I needed to filter out some fields, based on another value on the Entity Form and also based a specific value in the list items. Below are some of the code I used for this scenario, which will help you figure out your code.
$("#d365a_lookupfield_lookupmodal").find(".entity-grid").on("loaded", function () { });
var otherfieldvalue = window.parent.$("#d365a_otherfield option:selected").val();
$(this).children(".view-grid").find("tr").each(function () { });
var fieldtocheckvalue = $(this).find("td[data-attribute='d365a_fieldtocheck']").attr("data-value");
// Check condition 1 if (otherfieldvalue == 2) { // Check condition 2 and remove tr element if (fieldtocheckvalue == "false") { $(this).remove(); } }
Here's the full code.
// Trigger when the Lookup button is clicked. $("#d365a_lookupfield_lookupmodal").find(".entity-grid").on("loaded", function () { // Get the value of the other field (Note: you don't need this exact step but you may have other filter criteria) from the parent var otherfieldvalue = window.parent.$("#d365a_otherfield option:selected").val(); // Find all the tr elements $(this).children(".view-grid").find("tr").each(function () { // Find the td elements (the field) within each tr element which I wanted to check var fieldtocheckvalue = $(this).find("td[data-attribute='d365a_fieldtocheck']").attr("data-value"); // Check condition 1 if (otherfieldvalue == 2) { // Check condition 2 and remove tr element if (fieldtocheckvalue == "false") { $(this).remove(); } } }); });
This example will give some clues on how to implement your scenario.
Note: Only issue with this solution is that if you have say 50 records and first page shows 10, this code may remove 5 and show only 5 on the first page.
Hi,
See the link below.
Try the following code as described in the link.
$(document).ready(function(){ var label = new EntityOptionSet().GetOptionSetLabelByValue("entityName", "attributeName", value, languageCode);
label.hide();
});
Hope this helps.
Hi Luke
If you leave the control as a regular lookup, you can "filter" what values are available based on "Related Records Filtering" on the CRM form that you use as a basis for webform step/entity form.
Any reason why not to leave it as a regular lookup?
When you change the metadata to a dropdown, unfortunately I believe that this filtering no longer works.
Building out the javascript to remove various lookup items might be quite complex. I had looked into it before and I ended up having a developer create a custom asmx user control to filter the values in a drop down, and added a user control web form step.
A possible (but very clunky solution with hardcoded values) would be to add a regular option set to your CRM form with just the values you need and hide your lookup.
Based on the value chosen from the option set, in JavaScript set the lookup field to the corresponding value.
e.g.
if ($("abc_optionset").val == "1")
{
$("#abc_fieldname").val("294364bb-0bc7-e311-940a-06098be11d04");
}
Sorry for the crappy idea, but I hope it provides at least a bit of insight.
Cheers
Nick
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,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156