Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Show/hide multiple fields based on subgrid data

(0) ShareShare
ReportReport
Posted on by 5,007
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... 291,703 Super User 2024 Season 2 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,433 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans