Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Hiding Values in Option Set (Adxstudio)

Posted on by

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

  • lauralca Profile Picture
    lauralca 10 on at
    RE: Hiding Values in Option Set (Adxstudio)

    Hello Luke O,

    I have the same problem. How did you get it fixed?

    Thank you very much!

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    Nadeeja Bomiriya 6,804 on at
    RE: Hiding Values in Option Set (Adxstudio)

    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.

    • We need a 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 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 conditions and remove tr element
    // 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.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Hiding Values in Option Set (Adxstudio)

    Hi,

    See the link below.

    https://community.adxstudio.com/products/adxstudio-portals/documentation/developers-guide/knowledge-base/getting-option-set-value-label/

    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.

  • Suggested answer
    Nick.Doelman Profile Picture
    Nick.Doelman 1,947 Most Valuable Professional on at
    RE: Hiding Values in Option Set (Adxstudio)

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans