Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to hide and show fields on the form based on condition

(0) ShareShare
ReportReport
Posted on by 2

Hello All Experts,

I have a form which contains two lookups and two options fields.

I need to hide and show the two options fields based on certain values which are present in the dropdown are selected.

I have used the sdk.rest retrieve method, but my trouble is that when i am using first dropdown value to fetch the record and the same value in the successcallback method i am utilizing and in that successcallback i am again trying to retrieve the value of the another lookup but my code do not work.

is there any possibility i can directly choose the lookup value rather than lookup id.

it will really be appreciable if anyone can help me in this.

  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at
    RE: How to hide and show fields on the form based on condition

    Hi,

    Thank you for your query.

    If I understood correctly, you need to show or hide two options field based on a value selected in the lookup fields.

    And Instead of comparing based on GUIDs (lookup id), you need to compare values on lookup record names.

    In that case you can use following approaches:

    • Business Rules: create a business rule for your form and add conditions on the lookup field, and then show/or hide the field. For example:

    pastedimage1613557094432v1.png

    • Or you can register a JavaScript function on change of your lookups and get the name field code, here is sample for your reference:

    function onChangeofLookup(executionContext) {
    
    
        // get formContext
    
        var formContext = executionContext.getFormContext(); 
        
        var objLookup = formContext.getAttribute("").getValue();
        
        var lookupId = objLookup[0].id;
    
        var lookupName = objLookup[0].name;
    
        var lookupEntityName = objLookup[0].entityType;
        
        if (lookupName === "X" || lookupName === "Y") {
        
            formContext.getControl("").setVisible(true);
        
        }
    }

    If you need to do your comparisons, on other fields of the lookup record, its better to use the Web API to retrieve values from lookup record:

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrieverecord

    If you find any issue, please share the error details.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,000 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,850 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans