2

我在创建包含标签的新缺陷或用户故事时遇到了一些麻烦。我尝试了几种不同的方法,通常缺陷是在 Rally 中创建的,但没有附加标签。从 Rally API 和工具包的源代码来看,标签似乎应该在 ArrayList 中。这是我最近的尝试。如果有人能指出我正确的方向,我将不胜感激。

DynamicJsonObject itemToCreate = new DynamicJsonObject();
itemToCreate["project"] = project["_ref"];

ArrayList tagList = new ArrayList();

DynamicJsonObject myTag = new DynamicJsonObject();
myTag["_ref"] = "/tag/1435887928";

tagList.Add(myTag);
itemToCreate["Tags"] = tagList;
CreateResult itemToCreateResult = restApi.Create(workspace["_ref"], "defect", itemToCreate);
4

1 回答 1

2

你快到了:

 ArrayList tagList = new ArrayList();
 DynamicJsonObject myTag = new DynamicJsonObject();
 myTag["_ref"] = "/tag/2222";
 tagList.Add(myTag);
 myStory["Tags"] = tagList;
 updateResult = restApi.Update(createResult.Reference, myStory);

此代码创建一个用户故事,根据 ref 查找标签并将标签添加到故事:

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

namespace Rest_v2._0_test
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize the REST API
            RallyRestApi restApi;
            restApi = new RallyRestApi("user@co.com", "secret", "https://rally1.rallydev.com", "v2.0");

            //Set our Workspace and Project scopings
            String workspaceRef = "/workspace/11111"; //replace this OID with an OID of your workspace

            //Create an item
            DynamicJsonObject myStory = new DynamicJsonObject();
            myStory["Name"] = "abcdefg11";
            CreateResult createResult = restApi.Create(workspaceRef, "HierarchicalRequirement", myStory);
            DynamicJsonObject s = restApi.GetByReference(createResult.Reference, "FormattedID");
            Console.WriteLine(s["FormattedID"]);

            myStory["Description"] = "This is my story.";
            OperationResult updateResult = restApi.Update(createResult.Reference, myStory);

            ArrayList tagList = new ArrayList();
            DynamicJsonObject myTag = new DynamicJsonObject();
            myTag["_ref"] = "/tag/2222";
            tagList.Add(myTag);

            //Update the item 
            myStory["Tags"] = tagList;
            updateResult = restApi.Update(createResult.Reference, myStory);
        }
    }
}
于 2013-08-16T16:18:31.867 回答