我正在尝试以编程方式创建缺陷。当我将项目或用户字段作为变量传递给JsonObject时,我收到以下错误:
无法从“”/ user / 2 .........“”
解析对象引用代码:
newDefect.addProperty("SubmittedBy", username);
其中username =“/ user / 2 .........”
但如果我有以下代码:
newDefect.addProperty("SubmittedBy", "/user/2.........");
它过去了。我希望能够让程序动态地查找用户并能够获得引用,但到目前为止,当我尝试时,我得到了该错误。
有什么想法吗?
答案 0 :(得分: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);
}
}