Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help needed please for totalling values in a Grid

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
543 Views, 5 Replies

Help needed please for totalling values in a Grid

Hi, 

 

As part of a much longer script, I need to loop through each line of the Grid and add the value in the 'Adjusted hours' field on each row to the 'Adjusted hours' value on the next row etc  until I get the total.  I've got as far as getting it to add the value of each line to itself (not q the plan!), but not to the value on each subsequent row.  

 

I know on screen in the Grid that the Total is shown, but as far as I know, this is not a element that is available for use in scripting, hence needing to tell it in the script how to do this.  

 

The code I have so far for this is:

 

for (var gridindex in item.grid)
    {
     var Totadjhrs = item.grid[gridindex].TS_ADJ_HRS + item.grid[gridindex].TS_ADJ_HRS; 
    }

 I can see now why this adds the value to itself; what I don't know is what I need to write to get it to take one instance of the value and add it to the next one until it has completed all rows of the Grid and come out with the overall total.

 

Thanks for your help!

 

Fiona

 

 

5 REPLIES 5
Message 2 of 6
bastien.mazeran
in reply to: Anonymous

Hi Fiona,

 

One way would be to store the previous values in an array. As you loop through the grid records, you would push the current adjusted hours value to your array, then check for gridindex being strickly greater than zero and calculate the total value there by adding current adjusted hours value to value found in previous row (i.e. calling your array with gridindex minus one).

 

I hope this helps.

Regards,

 

 



Bastien Mazeran

Technical Support Specialist

Message 3 of 6
dvirh
in reply to: Anonymous

hi Fiona,

 

There are a couple of issues with your script. First, you are defining the variable inside the loop. Second, you are not adding the value to the prior sun. Try this instead:

 

var Totadjhrs = 0;

for (var gridindex in item.grid) { Totadjhrs = Totadjhrs + item.grid[gridindex].TS_ADJ_HRS; }
Hagay Dvir
Engineering Manager
Fusion Manage
Autodesk, Inc.
Message 4 of 6
bastien.mazeran
in reply to: Anonymous

Hi Fiona,

Here is code that worked for me:

 

var previousGridArr = [];
for (var gridindex in item.grid)
{
   var curValue = item.grid[gridindex].ADJUSTED_HOURS;
   previousGridArr.push(curValue);
   if (gridindex > 0) {
      previousVal = previousGridArr[gridindex - 1];
      var total = curValue + previousVal;
      item.grid[gridindex].ADJUSTED_HOURS = total;
   }
}

 

 

Regards,



Bastien Mazeran

Technical Support Specialist

Message 5 of 6
Anonymous
in reply to: dvirh

Thanks Hagay,

 

That's what I needed.  

 

Many thanks,

 

Fiona

 

 

Message 6 of 6
Anonymous
in reply to: bastien.mazeran

Thanks for your reply Bastien,

 

In this case, it's probably more than I need, but good to see an alternative way and to keep learning (or trying to!).  No doubt it will be of help to someone else at some point too.

 

Fiona

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report