Search code examples
.netrally

Rally API: How to update a story with new defects


I am new to using the Rally API for .NET and I would be very appreciative for any help. I have obtained the story object but I am not sure how to update it with a new defect. I can create new defects following various examples but they are not associated to any particular story. My current error brings back:

["Ignored JSON element hierarchicalrequirement.Defects during processing of this request."].


Solution

  • The collection of Defects on a HierarchicalRequirement is read-only, so you can't associate Defects to a Story by making changes to the Defect collection. What you can do, however, is to set the Requirement attribute of the Defect to the Ref of an existing Story, when either creating/updating Defects using the API. Here's a quick example:

    //Set our Workspace and Project scopings
    String workspaceRef = "/workspace/12345678910";
    String projectRef = "/project/12345678911";
    String userRef = "/user/12345678912";
    String storyRef = "/hierarchicalrequirement/12345678913";
    
    for (int i = 0; i < 3; i++)
    {
        DynamicJsonObject myDefect = new DynamicJsonObject();
    
        myDefect["Name"] = "My Defect from REST: " + i;
        myDefect["Priority"] = "Normal";
        myDefect["Workspace"] = workspaceRef;
        myDefect["Project"] = projectRef;
        myDefect["SubmittedBy"] = myUserReference;
        myDefect["Requirement"] = storyRef ;
    
        CreateResult createDefect = restApi.Create("Defect", myDefect);
        Console.WriteLine("Created: " + myDefect["Name"] + "\n");
    
        DynamicJsonObject fetchedDefect = restApi.GetByReference(createDefect.Reference, "FormattedID");
        Console.WriteLine("Created Defect with FormattedID: " + fetchedDefect["FormattedID"]);
    
    }
    

    Where the long integers are the ObjectID's (OID's) of the objects in Rally used in the ref's of interest.