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,091
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
  • Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Show/hide multiple fields based on subgrid data
    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
  • Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Show/hide multiple fields based on subgrid data
    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:
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,516 Super User 2025 Season 1 on at
    Show/hide multiple fields based on subgrid data
    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?

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans