1

我正在尝试以编程方式创建一个缺陷。当我将项目或用户字段作为变量传递给 JsonObject 时,出现以下错误:

无法解析来自“”/user/2.........“”的对象引用

代码:

newDefect.addProperty("SubmittedBy", username);

其中用户名 =“/user/2…………”

但如果我有以下代码:

newDefect.addProperty("SubmittedBy", "/user/2.........");

它通过了。我希望能够让程序动态查找用户并能够获得参考,但到目前为止,当我尝试时,我得到了那个错误。

有任何想法吗?

4

1 回答 1

1

在此代码中,对用户和项目的引用作为变量传递:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rally.RestApi;
using Rally.RestApi.Response;

class Program
{
    static void Main(string[] args)
    {

        RallyRestApi restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");
        DynamicJsonObject user = restApi.GetCurrentUser();
        String userRef = user["_ref"];
        String workspaceRef = "/workspace/1111";
        String projectRef = "/project/3333";

        DynamicJsonObject myStory = new DynamicJsonObject();
        myStory["Name"] = "abc12345";
        myStory["Project"] = projectRef;
        myStory["Owner"] = userRef;
        CreateResult createResult = restApi.Create(workspaceRef, "HierarchicalRequirement", myStory);
        myStory = restApi.GetByReference(createResult.Reference, "FormattedID", "Owner", "Project");
        Console.WriteLine(myStory["FormattedID"] + " " + myStory["Owner"]._refObjectName + " " + myStory["Project"]._refObjectName);
    }
}
于 2013-09-03T15:54:14.897 回答