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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Add Subgrid Column Total into another field in Dynamic 365 Online

(0) ShareShare
ReportReport
Posted on by 340

Hi All,

I have a Goal Entity. In that entity a Child Goal sub grid is there. I want to sum the Target field value into another field. I know that RollUp is the way to do this. But I dont have Rollup option available in that Entity. I have to do this using JS. Can anubody help me with code because i see lots of code in various blogs but as I am using Dynamic 365 Online so all the codes are not supported in this environment. 

Please help me with the code.

Thanks for your Suggestion.

8883.Pic.png

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Add Subgrid Column Total into another field in Dynamic 365 Online

    I think the following code will work for you:

    var targetTotal = 0;

    var allRows = Xrm.Page.getControl("ChildGoals").getGrid().getRows().getAll();

    allRows.foreach(function (currentRow) {

       var attributes = currentRow.getData().getEntity().getAttributes().getAll();

       attributes.forEach(function (attribute) {

           var attributeName = attribute.getKey();

           if (attributeName == "new_target") {

               targetTotal += attribute.getValue();

           }

       });

    });

    You will have to replace the name of the grid control and the attribute with your actual control names, but the rest should be the same. Hope this helps.

  • NILANKA SEKHAR PAUL Profile Picture
    340 on at
    RE: Add Subgrid Column Total into another field in Dynamic 365 Online

    Hi Aric,

    Thanks for your support.

    I apply your code with the Subgrid name and Attribute name and get the below error while form Loading.

    2642.Pic2.png

  • NILANKA SEKHAR PAUL Profile Picture
    340 on at
    RE: Add Subgrid Column Total into another field in Dynamic 365 Online

    Hi All,

    Is anyone can able to sorted out .

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Add Subgrid Column Total into another field in Dynamic 365 Online

    It is possible the grid is not yet loaded when you are calling this onLoad, so the get grid will return a null value, and that is why getRows is undefined. You might try to set a timeout, or do this based on a button click event or the OnSave event of the grid instead of onLoad.

    I have the exact same function working on my end.

    Take a look at the msdn article for using Grid events:

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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans