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)

Refresh Entity Form after adding row to a sub-grid.

(0) ShareShare
ReportReport
Posted on by

I have a scenario when I update certain fields on case entity whenever I add a record to custom entity's sub-grid which is on the case entity form. Fields on case form are updated via sync plugin which is triggered when the new custom entity record is created.

the fields on case form are updated but changes are not visible unless I manually refresh the case form.

Is there a way that I can refresh the case form whenever a record is added or removed from the sub-grid.

I do not want to refresh the form everytime sub-grid refreshes, so I need a solution other then addOnLoad function of sub-grid.

Any help on this is appreciated.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Try this:

    var recordcount = null;
    function OnLoad()
    {
        CheckRecordCount();
    }
    function CheckRecordCount() {
        try {
            setInterval(function () {
                if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("GRIDNAME") != null &&
                    Xrm.Page.getControl("GRIDNAME") != undefined) {
                    var rowcount = Xrm.Page.getControl("GRIDNAME").getGrid().getTotalRecordCount();
                    if (recordcount == null) { 
                        recordcount = rowcount;
                    } else if (recordcount != rowcount)
                        Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
                    }
                }, 5000);
        } catch (ex) {
            Xrm.Utility.alertDialog(functionName + "Errore: " + (ex.message || ex.description));
        }
    }

    Hope it helps.

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Community Member Profile Picture
    on at

    Hi Siddharth,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    ShivAgrawal Profile Picture
    10 on at

    The above given solution will not work since you are getting row count from the page itself which will always be unchanged if not refreshed manually.

    Instead of using this -- formContext.getControl("subgrid").getGrid().getTotalRecordCount();

    You can use webapi to get the record count from Backend.

    Also, at the if else condition you need to assign rowcount to recordcount

    else if (recordcount != rowcount) {
    recordCount = rowcount;
    formContext.getControl("subgrid").refresh();
    }

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
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#2
Wayne Walton Profile Picture

Wayne Walton 2

#2
SA-08121319-0 Profile Picture

SA-08121319-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans