1
votes

In the previous Rally Java REST WebService API SDK version 1.37, I could query for a Defect, and the ObjectIDs of its child Tasks (a One-To-Many field of Defect, meaning a Defect can have many Tasks) would also be included in the results.

However, it appears that in API version 2.0, the returned results do not include the ObjectIDs of any child One-to-Many objects, but instead only mention of how many there are (key = Tasks, value = {"_rallyAPIMajor":"2","_rallyAPIMinor":"0","_ref":"https://rally1.rallydev.com/slm/webservice/v2.0/Defect/1234567890/Tasks","_type":"Task","Count":5}).

Is there an easy way to find the ObjectIDs of all One-To-Many children, i.e. all the ObjectIDs of the Tasks associated to this Defect as part of my Defect query? I would rather not have to use each returned _ref, and use it to do the lookup (would be a lot of requests, one for each child).

Thank you.

1

1 Answers

1
votes

You can now query the child collections in the same way you would query a root level type.

I modified the following code example to do what you're looking for:

https://github.com/RallyTools/RallyRestToolkitForJava/blob/master/src/main/resources/examples/com/rallydev/rest/CollectionQueryExample.java

//Assumes you have a defect retrieved already
JsonObject taskInfo = defect.getAsJsonObject("Tasks");
int taskCount = taskInfo.get("Count").getAsInt();
System.out.println(String.format("\nTotal tasks: %d", taskInfo));

if(taskCount > 0) {
    QueryRequest taskRequest = new QueryRequest(taskInfo);
    taskRequest.setFetch(new Fetch("FormattedID", "Name", "State"));

    QueryResponse queryResponse = restApi.query(taskRequest);
    if (queryResponse.wasSuccessful()) {
        for (JsonElement result : queryResponse.getResults()) {
            JsonObject task = result.getAsJsonObject();
            System.out.println(String.format("\t%s - %s: State=%s",
                    task.get("FormattedID").getAsString(),
                    task.get("Name").getAsString(),
                    task.get("State").getAsString()));
        }
    }
}