October 27, 2015

Filtering on the Fly—Using JSON Queries to Filter Records with the TestTrack SDK

Helix ALM
Good news for developers who use the TestTrack SDK—we’ve made it easy to get a specific data set to work with in your SOAP applications. You can now retrieve a list of records and dynamically filter the results. What this means to you:
  • No need to pre-define filters to limit the data returned.
  • No need to process through large sets of data in your code.
  • More targeted results may improve the speed of your SOAP application.
TestTrack 2015.1 introduces the new getRecordListForTableWithQuery operation for retrieving issues, requirements, requirement documents, test cases, and test runs. With this operation, you can use a JSON query instead of a filter to limit returned records. Or, you can use a filter and a JSON query together. If you’re already familiar with the existing getRecordListForTable operation to retrieve data, learn more about the differences between it and the new operation.

Writing a JSON query is easy

We made it simple to create JSON queries for the getRecordListForTableWithQuery operation. When you’re working with filters or advanced find in the TestTrack Client, you can add the restrictions you want to use, view the resulting JSON query, and then copy and paste it into your code. You can make changes to the query in TestTrack and validate it to make sure it still works. Here are the three steps for getting a query into your code.

1. Enable JSON query debugging

To get started, enable JSON debugging in the TestTrack Client. Choose Tools > Local Options and then select the Advanced category. Select Enable JSON query debugging for filters and click OK. LocalOptionsAdvanced Enabling this option adds an Edit JSON button to the filter and advanced find dialog boxes. We’ll talk about that next.

2. Create a query in TestTrack

To easily* create a JSON query, use the TestTrack Client. When working with a filter or performing an advanced find, add the restrictions you want to use in the query and then click Edit JSON. Voilá! There’s your query. EditJSONQueryFilter You can tweak the query as needed, but make sure to click Validate Query when you’re done to make sure you didn’t break anything. TestTrack returns descriptive errors that can help you make changes. *If you like to do things the hard way, you can certainly write a query directly in your code. You’ll want to review information about supported restriction types and JSON query syntax. To make sure the syntax is correct or to debug it, paste it in the Edit JSON Query dialog box in the TestTrack Client and validate it.

3. Add the query to your SOAP application code

To add the JSON query to your code, copy it from the Edit JSON Query dialog box in TestTrack and paste it in the getRecordListForTableWithQuery operation in your code. Here is a C# example that retrieves the number, status, and summary for issues with ‘Crash – Data Loss’ or ‘Crash – No Data Loss’ selected in the Type field.
string[] columnNames = {"Number", "Status", "Summary"};

CTableColumn[] columns = new CTableColumn[columnNames.Length];

for (int x = 0; x < columns.Length; x++)
{
columns[x] = new CTableColumn();
columns[x].name = columnNames[x];
}

string query = "{'Type': ['Crash - Data Loss', 'Crash - No Data Loss']}";
CRecordListSoap recList = ttsdk.getRecordListForTableWithQuery(cookie, "Defect", "", query, columns);

Troubleshooting

If you have any problems using the getRecordListForTableWithQuery operation, you may need to update your SOAP application to use the current version of the TestTrack SDK WSDL. Here’s more information. If your queries fail, remember you can validate them in the TestTrack Client to troubleshoot. The TestTrack SDK help includes more information about using the getRecordListForTableWithQuery operation.