I ve reduced my code to the following short example. In it, I want to query for a set of iterations, and then in the callback, loop over the iterations and sum the resources. There is a global variable in which I d like to store the sum... but I can t get this to work.
The specific problem is that the query (and associated callback) are run after the other processing.
<html><!-- COMMENT -->
<meta name="Name" content="YOUR APP NAME HERE" />
<meta name="Version" content="0.1" />
<meta name="Vendor" content="YOUR COMPANY NAME HERE" />
<!-- Rally SDK --> <script type="text/javascript" src="/apps/1.25/sdk.js"></script>
<!-- App script --> <script>
var rallyDataSource; var resourceSum = -1;
function ProcessIterations(results) {
alert("In ProcessIterations");
var resourceSum = 0;
for (iIter = 0; iIter < results.iterations.length; iIter++) {
var iteration = results.iterations[iIter] ;
resourceSum += iteration.Resources;
}
alert("In ProcessIterations, resourceSum="+resourceSum); }
function queryError () {
alert("A query error occurred"); }
function runMainQuery() { var today = dojo.date.stamp.toISOString(new Date(), {milliseconds: true, zulu: true});
var queryObject = {
key: "iterations",
type: "Iteration",
fetch: "Name,ObjectID,Resources,Project",
order: "EndDate asc",
query: "(Project.ObjectID != "__PROJECT_OID__")"
};
rallyDataSource.findAll(queryObject, ProcessIterations, queryError); }
function Main() { rallyDataSource = new rally.sdk.data.RallyDataSource("__WORKSPACE_OID__", "__PROJECT_OID__",
"__PROJECT_SCOPING_UP__", "__PROJECT_SCOPING_DOWN__");
runMainQuery() ;
var tableConfig = {
columnKeys : [ planEst ],
columnHeaders : [ Plan Estimate ] }; var table = new rally.sdk.ui.Table(tableConfig); table.setCell(0,0,resourceSum) ; table.display("app_div");
}
rally.addOnLoad(Main);
</script> <body>
<div id="app_div"></div>
<div id="error_div"></div> </body> </html>