web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Show/hide multiple fields based on subgrid data

(0) ShareShare
ReportReport
Posted on by 5,514
Hi, 
 
I need to show/hide 3 fields based on subgrid data.
 
If subgrid contains any record then fields should be hidden .
 
Or if subgrid don't contain data show fields 
 
 
How can I achieve this 
 
Any links or example would be great full
 
Tia
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,051 Super User 2025 Season 2 on at
    Hi Sandeep,
     
    You can write x++ coding to achieve this on the Active() method of the data source that contains the fields which are conditionally shown. You can then check if there are related records in the table of the sub grid. 
    What should happen if there was initially no record in the sub grid, but a user would add data on the form? Should it then also trigger logic to hide these fields?
  • Leah Ju Profile Picture
    Microsoft Employee on at
    Hi Partner,
    You can use create one Javascript(web Resource) in CRM to achiev eyour goal.
    1)Get SubGird Record Count
    2)Hide or show fields:
    Test:
    --Hide Fax(fax) and Relationship Type(customertypecode) fields based on 'Contacts' sub-grid.
    1)Js Code:
    function hideBasedOnsubgridcount(executionContext) {
        setTimeout(function () {
            var formContext = executionContext.getFormContext();
            if (formContext !== null && formContext != "undefined") {
                var accountgridname = "Contacts";
                var count = formContext.getControl(accountgridname).getGrid().getTotalRecordCount();
     
                if (count == 0) {
                    formContext.getControl("customertypecode").setVisible(true);
                    formContext.getControl("fax").setVisible(true);
     
                }
                else {
                    formContext.getControl("parentaccountid").setVisible(false);
                    formContext.getControl("fax").setVisible(false);
                }
     
            }
        }, 15000);
    2)Add web resource to on Load event:
    3)Publish.
    4)Result:
  • Leah Ju Profile Picture
    Microsoft Employee on at
    Hi Partner,
    Was my answer helpful? 
    If it was helpful, can you verify it?
    If you have any questions, please feel free to contact me.
    Regards,
    Leah

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 49 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans