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 CRM (Archived)

Show/Hide sub grid New(+) button base on its total record count

(0) ShareShare
ReportReport
Posted on by

Hi,

I'd like to show/hide the new(+) button of sub-grid on the form, and I try the solution Show or hide the 'Add New' button on form sub-grid based on the value on the form then I can hide the '+' button successfully.

The other thing is using Xrm.Page.getControl("sub-grid-name").getGrid().getTotalRecordCount() in setTimeout function, then I can get the total record counts in sub-grid.

But how can I implement the enable rule on Ribbon(control the display) right after I get the right record count in sub-grid.

I put the setTimeout function before I return true or false for enable rule, but it doesn't work.  It just shows the default grid before I get the counts number.

Is there any solution?

Thanks for your help.

*This post is locked for comments

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    Hi,

     according to that article, you need to call "save" to refresh subgrid command bar.. Might want to combine it with grid "onload":

    msdn.microsoft.com/.../dn932126.aspx

     (try calling "save" from the onload.. maybe store previous record count in a javascript variable, compare to the current, and, then, call save if they are different)

  • Community Member Profile Picture
    on at

    Thanks for your reply.

    And there is another thing is that when I click associated view of the sub-grid, then create a new record, it will trigger onload function and I can get the latest record counts.  But when I delete it, it will not fire onload(), how can I get the records counts after deleting it?  Thanks.

  • Community Member Profile Picture
    on at

    The scenario is that when there are more than 1 record, it will not allow user to create (so I need to hide + button).

    However, if user delete the records, the button should be shown again.

    I have no idea which event it will be fired when I delete it so that I can write some code in it.

  • VJ7 Profile Picture
    on at

    Hi, I need to hide subgrid button based on record count. If you were able to resolve the issue, could you share the code you have tried?

    I tried using settimeout but it didn't work.

  • sumit verma jbp Profile Picture
    5 on at

    Hi,

    According to you scenario i have suggest you this is only solve by Security model. same situation i  handle in my one project.

    you can restrict create permission on child entity.

  • VJ7 Profile Picture
    on at

    Hi, I can't do it through security model since I'm not restricting users from creating subgrid records. I need to stop them creating more than one.

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans