问题
I'm using the RallyRestToolkitFor.NET and I'm pulling information from Rally tasks into our back office system. It is all working well except I'm having trouble fetching the name of the "Owner" of the task.
In fact, I can't seem to pull any information from the Owner. Below is a code snippet so you can see what I'm doing. It works great for the Description and FormattedID but the Owner name returned in the QueryResult is blank when it's actually set in Rally.
I've tried "Owner", "User", "User.Name", and nothing has worked. I guess I'm just stumped on how to retrieve the Owner Name on a task. However, I can query on Owner.Name
just fine, but I'm not able to fetch it in the list. Does anyone have any ideas?
Request request = new Request("task");
request.Fetch = new List<string>() {"Owner.Name", "Description", "FormattedID" };
request.Query = new Query("Project.Name", Query.Operator.Equals, "My Project");
QueryResult queryResult = restApi.Query(request);
foreach (var result in queryResult.Results)
{
ownerName = result["Owner.Name"];
}
回答1:
You can just fetch Owner and then also include individual fields from the User object type right in the same fetch:
request.Fetch = new List<string>() {"Owner", "UserName", "DisplayName" };
and then in the response:
owner = result["Owner"]
if(owner != null)
{
ownerName = owner["UserName"]
}
This same concept should work for any child object sub types in WSAPI.
来源:https://stackoverflow.com/questions/32621290/what-is-the-proper-way-to-fetch-the-owner-name-of-a-rally-task