Rally Rest API .NET Toolkit使用标签创建缺陷/用户故事

时间:2013-08-16 04:05:30

标签: rally

我在创建包含标签的新缺陷或用户故事时遇到了一些麻烦。我尝试了几种不同的方法,通常是在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);

1 个答案:

答案 0 :(得分: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);
        }
    }
}