1

我正在查询一个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);

它返回空值。

为什么这不起作用?当它是分层要求时,这两个查询都可以工作。

使用 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;
        }
4

1 回答 1

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"]);
                }

            }
        }
    }
}
于 2013-09-16T16:32:54.397 回答