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 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.

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

    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

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 41 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 39

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans