我正在查询PortfolioItem/Mmf
。这很好用:
new Request("PortfolioItem/Mmf")
{
ProjectScopeUp = false,
ProjectScopeDown = true,
Fetch = new List() { "Name", "Description", "FormattedID", "LastUpdateDate", "Owner", "Children" },
Query = new Query("FormattedID", Query.Operator.Equals, _formattedID)
};
但是当我查询引用地址(我可以在浏览器上打开并完美检查json)时,这样:
//_childFetch contains the same Fetch string list from the previous query
var childObject = m_rallyApi.GetByReference(_childRef, _childFetch);
它返回null。
为什么这不起作用?两个查询在分层要求时都有效。
修改 使用GetByReference()
的方法的完整代码private HierarchicalRequirement GetUserStoryByReference(string _childRef, string[] _childFetch)
{
HierarchicalRequirement userStory = null;
var childObject = m_rallyApi.GetByReference(_childRef, _childFetch);
if (childObject["Children"].Count == 0)
{
userStory = new HierarchicalRequirement(childObject);
}
else
{
if (childObject["Children"].Count > 0)
{
userStory = new HierarchicalRequirement(childObject);
foreach (var child in childObject["Children"])
{
userStory.Children.Add(GetUserStoryByReference(child["_ref"], _childFetch));
}
}
}
return userStory;
}
答案 0 :(得分:1)
我提交了一个缺陷。我得到了
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
使用时
String featureRef = queryResults.Results.First()._ref;
Console.WriteLine(featureRef); //prints correctly
DynamicJsonObject feature = restApi.GetByReference(featureRef, "Name");
String name = feature["Name"];
最后一行是它窒息的地方。 与UserStories及其子项相同的代码。
如果我避免使用GetByReference
,它适用于PortfolioItems。这是代码:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;
namespace FindTFchildren
{
class Program
{
static void Main(string[] args)
{
RallyRestApi restApi;
restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");
String projectRef = "/project/12352814790"; //replace this OID with an OID of your project
Request fRequest = new Request("PortfolioItem/Feature");
fRequest.Project = projectRef;
fRequest.Workspace = workspaceRef;
fRequest.Fetch = new List<string>() { "FormattedID", "Name", "UserStories"};
fRequest.Query = new Query("FormattedID", Query.Operator.Equals, "F3");
QueryResult queryResults = restApi.Query(fRequest);
foreach (var f in queryResults.Results)
{
Console.WriteLine("FormattedID: " + f["FormattedID"] + " Name: " + f["Name"]);
Console.WriteLine("Collection ref: " + f["UserStories"]._ref);
Request childrenRequest = new Request(f["UserStories"]);
QueryResult queryChildrenResult = restApi.Query(childrenRequest);
foreach (var c in queryChildrenResult.Results)
{
Console.WriteLine("FormattedID: " + c["FormattedID"] + " Name: " + c["Name"]);
}
}
}
}
}