Data Examples

Deprecation Warning! The content below is only applicable for use within deprecated 1.x versions of CA Agile Central's App SDK. Use of the component(s) and code on this page is not supported. To develop custom apps within our current environments, please see App SDK 2.0 documentation.

Example Name Description Actual Query
Simplest example Simple query config and results processing Defect
Simple query Uses query qualification syntax Defects whose State = Open
Multiple queries Returns completed stories and fixed defects using a single findAll Completed stories and fixed defects
Attribute values Uses query attribute syntax to retrieve allowed attributes The allowed UserStory Schedule State, Defect State, TestCase Last Verdict values
SubField query Query qualification uses Name field of iteration attribute in a UserStory Stories where Iteration.Name = a specific value
Object count Uses placeholder syntax to utilize information returned from another query Count of Defects whose State = Fixed
Placeholder query In some cases, you can make a reference in one query to results from another query All defects owned by the logged-in user

Simplest example

In this example, a query config object is defined to be able to return the Name, State, and Severity attributes from CA Agile Central defects. When the query results are returned, this information is shown as lines of text with the attribute values separated by commas.

Copy and paste the following example code into a custom app.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html>
<head>
   <meta name="Name" content="App Example: Defect List"/>
   <title>Defect Query Example</title>
   <script type="text/javascript" src="/apps/1.26/sdk.js"></script>
   <script>

     function defectsExample() {
       var displayDefects = function(results) {
         var defectsInfo = "";
         var defect = "";
         for (i=0 ; i < results.defects.length ; i++) {
           defect = results.defects[i];
           defectsInfo += defect.Name +
                       ', ' + defect.State +
                       ', ' + defect.Severity + '<br>';
         }
         var aDiv = document.getElementById("aDiv");
         aDiv.innerHTML = '<strong>Name, State, Severity</strong><br/>';
          aDiv.innerHTML += defectsInfo;
       };

       var queryConfig = {
          type : 'defect',
          key : 'defects',
          fetch: 'Name,State,Severity'
       };

        var rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                                                  '__PROJECT_OID__',
                                                   '__PROJECT_SCOPING_UP__',
                                                  '__PROJECT_SCOPING_DOWN__'
);
       rallyDataSource.findAll(queryConfig, displayDefects);
     }

     rally.addOnLoad(defectsExample);
  </script>
</head>
<body>
  <div id="aDiv"></div>
</body>
</html>

Simple query

In this example, a query config is created that provides a selection criteria for the query property such that only open defects are retrieved. Also, note that the fetch fields of Name and Priority are explicitly specified. The results are displayed on the page with a line per defect after the results are retrieved.

Copy and paste the following example code into a custom app.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html>
<head>
   <meta name="Name" content="App Example: Open Defects List"/>
   <title>Open Defects List</title>
   <script type="text/javascript" src="/apps/1.26/sdk.js"></script>
  <script type="text/javascript">

    function openDefectsExample() {
      var showOpenDefects = function(results) {
        var defect;
        var aDiv = document.getElementById("aDiv");
        aDiv.innerHTML = '<b>Open Defects</b><br/>';
        aDiv.innerHTML += ' Priority - Name<br/>';
        for (var i=0 ; i < results.defects.length ; i++) {
          defect = results.defects[i];
           aDiv.innerHTML += defect.Priority + ' - ' + defect.Name + '<br>';
}
      };

      queryConfig = {
        type : 'defect',
        key : 'defects',
        query: '(State = Open)',
        fetch: 'Name,Priority'
      };

      var rallyDataSource;
      rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                               '__PROJECT_OID__',
                               '__PROJECT_SCOPING_UP__',
                               '__PROJECT_SCOPING_DOWN__'
);
      rallyDataSource.findAll(queryConfig, showOpenDefects);
    }

    rally.addOnLoad(openDefectsExample);
   </script>
</head>
<body>
  <div id="aDiv"></div>
</body>
</html>

Multiple queries

This example demonstrates that multiple queries can be specified. A query config array is constructed to fetch the FormattedID and Name attributes from the HierarchicalRequirement (User Story) and defect entities in CA Agile Central. When the queries for both have been executed and the results returned in a results object (see Processing Query Results), a callback function is called to display the results on the page. Because the attributes fetched are the same between the target entities, the showResults callback function is agnostic with respect to the actual entity. It is important to remember that although one query may take a longer or shorter time to execute than others supplied in the query config array, the callback function is called only once, when all the queries have completed.

Copy and paste the following example code into a custom app.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html>
<head>
   <meta name="Name" content="App Example: Multiple Queries" />
   <title>Multiple Queries Example</title>
   <script type="text/javascript" src="/apps/1.26/sdk.js"></script>
   <script type="text/javascript">

    function multipleQueriesExample() {

      var showResults = function(results) {
        var aDiv = document.getElementById("aDiv");
        aDiv.innerHTML = "<b>multipleQueriesExample</b><br>";
        for (property in results) {
          aDiv.innerHTML += property + "<br>";
          var artifact;
          for (var i=0 ; i < results[property].length ; i++) {
             artifact = results[property][i];
             aDiv.innerHTML += "&nbsp;" + artifact.FormattedID + " - " + artifact.Name + "<br>";
           }
       }
     };

     var queryConfig = [];
     queryConfig[0] = {
      type : 'HierarchicalRequirement',
      key : 'stories',
      query: '(ScheduleState = Completed)',
      fetch: 'Name,FormattedID'
     };
     queryConfig[1] = {
      type : 'defect',
      key : 'defects',
      query: '(State = Fixed)',
      fetch: 'Name,FormattedID'
     };

    var rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                                     '__PROJECT_OID__',
                                     '__PROJECT_SCOPING_UP__',
                                     '__PROJECT_SCOPING_DOWN__'
);
    rallyDataSource.findAll(queryConfig, showResults);
  }

   rally.addOnLoad(multipleQueriesExample);
   </script>
</head>
<body>
   <div id="aDiv"></div>
</body>
</html>

Attribute values query

This example demonstrates how to set up a query config specification to retrieve the allowed attribute values for specific attributes in separate CA Agile Central entities. The allowed values for the Schedule State attribute from the HierarchicalRequirement entity (User Story) are shown. The allowed values for the State attribute from the defect entity are shown. The allowed values for the Last Verdict attribute from the TestCase entity are shown.

Copy and the following example code into a custom app.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html>
<head>
  <meta name="Name" content="App Example: Attribute Values" />
   <title>Attribute Values Example</title>
   <script type="text/javascript" src="/apps/1.26/sdk.js"></script>
   <script type="text/javascript">

  function attributeQueryExample() {

     var showAttributeValues = function(results) {
      var aDiv = document.getElementById("aDiv");
      aDiv.innerHTML = '<b>attributeQueryExample</b><br>';
      for (var property in results) {
        aDiv.innerHTML += "&nbsp;<b>" + property + "</b><br>";
        for (var i=0 ; i < results[property].length ; i++) {
          aDiv.innerHTML += "&nbsp;&nbsp;" + results[property][i] + "<br>";
        }
      }
     };

    var queryConfig = [];
    queryConfig[0] = {type: 'Hierarchical Requirement',
            key : 'storyStates',
            attribute: 'Schedule State'
            };
        queryConfig[1] = {type: 'Defect',
            key : 'defectStates',
            attribute: 'State'
            };
    queryConfig[2] = {type: 'Test Case',
             key : 'testCaseStates',
            attribute: 'Last Verdict'
             };

    var rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                                     '__PROJECT_OID__',
                                     '__PROJECT_SCOPING_UP__',
                                     '__PROJECT_SCOPING_DOWN__'
);
    rallyDataSource.findAll(queryConfig, showAttributeValues);
   }

   rally.addOnLoad(attributeQueryExample);

   </script>
</head>

<body>
   <div id="aDiv"></div>
</body>
</html>

SubField query

The following example shows how to query on the relationship of an object. In this case we show how to query on the iteration name of a user story.

Copy and paste the following example code into a custom app.

Note: You will need to change the iteration name in this code for your query to return results.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html>
<head>
   <meta name="Name" content="SubField Query" />
   <title>SubField Query Example</title>
   <script src="/apps/1.26/sdk.js"></script>
  <script type="text/javascript">

  function subFieldQueryExample() {

    var showStories = function(results) {
      var aDiv = document.getElementById("aDiv");
      aDiv.innerHTML = "<b>subFieldQueryExample</b><br>";
      var story;
      for (var i=0; i < results.stories.length; i++) {
        story = results.stories[i];
         aDiv.innerHTML += story.ScheduleState + ' - ' + story.Name + '<br>';
       }
     };

     queryConfig = {
       type : 'hierarchicalrequirement',
       key : 'stories',
       query: '(Iteration.Name = "Iteration 205")',
       fetch: 'Name,ScheduleState'
     };

     rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                                         '__PROJECT_OID__',
                                         '__PROJECT_SCOPING_UP__',
                                         '__PROJECT_SCOPING_DOWN__'
);
    rallyDataSource.findAll(queryConfig, showStories);
   }

   rally.addOnLoad(subFieldQueryExample);
  </script>
</head>
<body>
   <div id="aDiv"></div>
</body>
</html>

Object count

This example shows how to construct a query config so that you can obtain a count of qualifying defects (those that have been fixed). The placeholder construct is used to reference results of another query.

Copy and paste the following example code into a custom app.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html>
<head>
   <meta name="Name" content="App Example: Fixed Defects Count" />
   <title>Fixed Defects Count Example</title>
   <script type="text/javascript" src="/apps/1.26/sdk.js"></script>
   <script type="text/javascript">

   function sizeExample() {
    var displayResultCount = function(results) {
      document.getElementById('aDiv').innerHTML = 'Fixed Defects: ' + results.defectCount;
    };

     var queryConfig = [];
     queryConfig[0] = { type : 'defect',
           key : '#fixedDefects',
           query: '(State = "Fixed")'
         };
    queryConfig[1] = { key: 'defectCount',
           placeholder: '${#fixedDefects/size}'
        };

        var rallyDataSource;
rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                                            '__PROJECT_OID__',
                                            '__PROJECT_SCOPING_UP__',
                                            '__PROJECT_SCOPING_DOWN__'
);
    rallyDataSource.findAll(queryConfig, displayResultCount);
   }

   rally.addOnLoad(sizeExample);
   </script>
</head>
<body>
   <div id="aDiv"></div>
</body>
</html>

Placeholder query

This example demonstrates how you can reference specific information returned by a query in another query. The example queries and displays all defects owned by the logged-in user. An initial query is used to obtain the DisplayName of the logged-in user. A related query uses the DisplayName as a query qualifier to limit the defects selected to those owned by the logged-in user. The specific syntax wraps the reference using the format of ${key.attribute}.

Copy and paste the following example code into a custom app.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
<html>
<head>
   <meta name="Name" content="App Example: Placeholder Query" />
   <title>Placeholder Query Example</title>
   <script type="text/javascript" src="/apps/1.26/sdk.js"></script>
   <script type="text/javascript">

   function placeholderQueryExample() {

    var showDefectsByOwner = function(results) {
      var aDiv = document.getElementById('aDiv');
      aDiv.innerHTML = '<b>correlatedQueryExample</b><br>';
       var defect;
       for (i=0; i < results.userDefects.length ; i++) {
        defect = results.userDefects[i];
        aDiv.innerHTML += "&nbsp;" +
                defect.State + " " +
                defect.Owner.DisplayName + " " +
                defect.Name + "<br>";
      }
     };

    var queryConfig = [];
    queryConfig[0] = { type : 'user',
               key : 'user',
              fetch: 'UserName'
            };
    queryConfig[1] = { type : 'defect',
               key : 'userDefects',
               query: '(Owner.UserName = ${user.UserName})',
              fetch: 'Name,State,Owner,DisplayName'
             };

    var rallyDataSource;
    rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                                                 '__PROJECT_OID__',
                                                '__PROJECT_SCOPING_UP__',
                                                 '__PROJECT_SCOPING_DOWN__'
);
    rallyDataSource.find(queryConfig, showDefectsByOwner);
   }

   rally.addOnLoad(placeholderQueryExample);
   </script>

</head>
<body>
   <div id="aDiv"></div>
</body>
</html>

Feedback

Need more help? The CA Agile Central Community is your one-stop shop for self-service and support. To submit feedback or cases to CA Agile Central Support, find answers, and collaborate with others, please join us in the CA Agile Central Community.