I shortened my code to the following short example. In it, I want to request a set of iterations, and then in the callback, iterate over the iterations and summarize the resources. There is a global variable in which I would like to store the amount ... but I cannot get this to work.
The specific problem is that the request (and the associated callback) is launched after another processing.
<html> <meta name="Name" content="YOUR APP NAME HERE" /> <meta name="Version" content="0.1" /> <meta name="Vendor" content="YOUR COMPANY NAME HERE" /> <script type="text/javascript" src="/apps/1.25/sdk.js"></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>
source share