2013-08-16 93 views
2

我在創建包含標籤的新缺陷或用戶故事時遇到了一些麻煩。我嘗試了幾種不同的方式,通常缺陷是在拉力賽中創建的,但沒有附加任何標籤。從查看Rally API和工具包的源代碼,看起來標籤應該位於ArrayList中。這是我最近的嘗試。如果任何人都能指出我正確的方向,我將不勝感激。Rally Rest API .NET工具包用標籤創建缺陷/用戶故事

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); 

回答

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); 

此代碼創建一個用戶故事,認定基於裁判標籤,並增加了一個標籤一個故事:

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("[email protected]", "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); 
     } 
    } 
} 
相關問題