This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Rollup from Grid

Graham McCall - Thursday, April 21, 2011 12:09 PM:

 

 

 

 

 

 

Hi All,

I want to rollup some values from a grid.  The client method below works fine as long as the related item is displayed first along the relationship tabs (lowest sort order).  If the sort order on the Relationship Item is not set so it is the first then it fails.  Is there a way to make this work when the related items are displayed in the 2nd, 3rd position etc..


document.MilesRollupFromGrid = function(){
  var totalmiles = 0;
  var q = document.thisItem;
  var rate = q.getProperty("mile_rate1");
  var grid = top.relationships.frames[0].grid;
  var ids  = grid.getAllItemIds('|').split('|');
  for (var i=0; i<ids.length; ++i)  {
    var id   = ids[i];
    var mileage = grid.cells(id,9).GetValue();
    totalmiles += mileage / 1;
  }
  var value = rate * totalmiles;
  handleItemChange("mileage_value",value);
  handleItemChange("mileage_total",totalmiles);
};

Graham



Brian - Saturday, April 30, 2011 8:59 AM:

Hi Graham,

There are probably a couple of ways of doing this.

If you know the name of the tab then you can use this code to determine which "top.relationship.frames[xx].grid" you need to target.

var targetTab = -1;
var tb = this.getActiveToolbar();
var tabbar = parent.relationships.relTabbar;
var tabIds_array = tabbar.GetTabOrder("|").split("|");
for ( var t = 0; t<tabIds_array.length; t++)
{
    var tabLabel = tabbar.GetTabLabel(tabIds_array[t]);
    if ( tabLabel == "target tab name") { targetTab = t; break;}
}

then just put "targetTab" into your existing code.

Hope this helps.

Brian.