Search code examples
c#.netrally

RallyRestToolkitFor.NET - Defect Duplicates


I have an MVC application that we are using to display defects to customers. It is using the RallyRestToolkitFor.NET to get this information.

But I need to get a list of all of the duplicates of a defect and I'm not sure how I can achieve this.

Normally, I would get associated objects such as testcases by querying for

request = new Request("testcase")
                      {
                          Fetch =
                              new List<string>()
                              {
                                  "FormattedID",
                                  "Name",
                                  "LastRun",
                                  "LastVerdict"
                              },
                          Query =
                              new Query("WorkProduct.FormattedID", Query.Operator.Equals, "DE123")
                      };

But I can't see how I can acheive the same for duplicates as there is no 'parent' concept.

Can you help?


Solution

  • Here is code which accesses Duplicates collection on a defect:

    namespace FindDefectDuplicates
    {
        class Program
        {
            static void Main(string[] args)
            {
                RallyRestApi restApi;
    
                restApi = new RallyRestApi("[email protected]", "secret", "https://rally1.rallydev.com", "v2.0");
                String workspaceRef = "/workspace/1111";
                String projectRef = "/project/2222";
                bool projectScopingUp = false;
                bool projectScopingDown = false;
    
                Request defectRequest = new Request("defect");
                defectRequest.Workspace = workspaceRef;
                defectRequest.Project = projectRef;
                defectRequest.ProjectScopeUp = projectScopingUp;
                defectRequest.ProjectScopeDown = projectScopingDown;
    
                defectRequest.Fetch = new List<string>()
                    {
                        "Name",
                        "FormattedID",
                        "Duplicates"
                    };
    
                defectRequest.Query = new Query("FormattedID", Query.Operator.Equals, "DE123");
                QueryResult queryDefectResults = restApi.Query(defectRequest);
                foreach (var d in queryDefectResults.Results)
                {
                    Console.WriteLine("FormattedID: " + d["FormattedID"] + " Name: " + d["Name"]);
                    Console.WriteLine("Collection ref: " + d["Duplicates"]._ref);
                    Request duplicatesRequest = new Request(d["Duplicates"]);
                    QueryResult queryDuplicatesResult = restApi.Query(duplicatesRequest);
                    foreach (var duplicate in queryDuplicatesResult.Results)
                    {
                        Console.WriteLine("FormattedID: " + duplicate["FormattedID"] + " Name: " + duplicate["Name"]);
                    }
    
                }
            }
        }
    }