我在查询一个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。
为什么这不管用?当这是一个层次化的需求时,这两个查询都可以工作。
使用()编辑方法的完整代码
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;
}发布于 2013-09-16 16:32:54
我提交了一个缺陷。我得到了
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"]);
}
}
}
}
}https://stackoverflow.com/questions/18765353
复制相似问题