Reputation: 2140
I'm searching for user stories in my backlog successfully using arguments like US1, US4
. However, when a client tried to query for a feature using the letter F
, a user story with the same number was retrieved.
Then I tested with a defect - querying for DE1
retrieves US1
. But also, querying for any letters XX1
will also retrieve the US and the given #. My code for querying is:
public HierarchicalRequirement getUserStoryById(string _formattedID)
{
// I created this class with only the properties (bellow) I'm using
HierarchicalRequirement userStory = null;
Request storyRequest = new Request("hierarchicalrequirement")
{
ProjectScopeUp = false,
ProjectScopeDown = true,
Fetch = new List<string>()
{
"Name",
"ObjectID",
"FormattedID",
"LastUpdateDate",
"Owner",
"Children",
"Description",
"RevisionHistory",
"Revisions"
},
Query = new Query("FormattedID", Query.Operator.Equals, _formattedID)
};
try
{
QueryResult queryStoryResults = m_rallyApi.Query(storyRequest);
if (queryStoryResults.Results.Count() > 0)
{
var myStory = queryStoryResults.Results.First();
//Recursively gets a HierarchicalRequirement and its child by the reference value
userStory = GetUserStoryByReference(myStory["_ref"]);
}
}
catch (...){
}
return userStory;
}
Am I missing something really obvious here? Why I can't query for anything else than User Stories? When I first create the Request
object should it be something different from new Request("hierarchicalrequirement")
(maybe "defect" or "feature")?
Thank you
Upvotes: 1
Views: 1308
Reputation: 5966
The request must specify the work item type. Using "hierarchicalrequirement" with intent to query on defects, features, testcases, tasks will not work. FormattedIDs are unique within the same workspace, but you may have DE123, and US123, and TA123 and TS123 in the same workspace, and the work item type must be set accordingly.
Here is an example of query for defects:
class Program
{
static void Main(string[] args)
{
RallyRestApi restApi = new RallyRestApi("[email protected]", "secret", "https://rally1.rallydev.com", "v2.0");
String workspaceRef = "/workspace/1111";
String projectRef = "/project/2222";
Request dRequest = new Request("Defect");
dRequest.Workspace = workspaceRef;
dRequest.Project = projectRef;
dRequest.Fetch = new List<string>()
{
"Name",
"FormattedID",
};
var fid = "DE1";
dRequest.Query = new Query("FormattedID", Query.Operator.Equals, fid);
QueryResult queryResults = restApi.Query(dRequest);
DynamicJsonObject defect = queryResults.Results.First();
String defectRef = defect["_ref"];
Console.WriteLine(defectRef);
Console.WriteLine("FormattedID: " + defect["FormattedID"] + " Name: " + defect["Name"]);
//...........
Upvotes: 2