Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Sum a column from a Subgrid using Javascript

(0) ShareShare
ReportReport
Posted on by 10

Hello, I'm trying to sum all register from a column from a Subgrid using a Javascript, I'm not really sure if Im doing correctly because the code is not working and also I added the event handler

on the new field I added to show the value of the Sum but this handler only works on onChange I can't add the event on the subgrid, if anyone can point me in the right direction , this is my code.

function totalHours(executionContext)
{
 debugger;
    var formContext =executionContext.getFormContext();
     
    if (formContext.getAttribute("Visit_Times").getValue() != null) 
    {
       var count = formContext.getControl("Visit_Times").getGrid().getTotalRecordCount();
       
       for(i = 0; i < count; i  ) {
       var gridControl = formContext.getControl('Visit_Times').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('Onsite time').getValue();
      var cellValue = gridControl;
      cellValue = cellValue.replace( /,/,"." );
        var sum = sum   parseFloat(cellValue);
      }
   }
formContext.getAttribute('new_TotalOnSite').setValue(sum);
}

I'm not really sure in which part I'm making the mistake.

Thank you.

Kind Regards,

Jorge.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Sum a column from a Subgrid using Javascript

    Hi JorgeDiaz,

    Please refer to this thread: Total amount of a dynamic filtered data in a sub-grid - Dynamics 365 General Forum Community Forum

    This thread has a similar demand as yours and I provide the code sample to achieve this. You could have a try with that.

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,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,760 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans