RallyAPI:如何创建UserStory并将其与功能相关联?

时间:2015-11-20 15:39:16

标签: c# api rally

所以,我正在编写一个应用程序来“充实”拉力赛中的新客户。它将有工具来创建将首先添加的模板:

  1. 添加'功能'
  2. 在“功能”下添加“UserStories”
  3. 单独在“UserStories”下添加“任务”
  4. 我已经找到了第1步。但是如何将任何我无法从可怕和神秘的文档中找出来的东西联系起来。这是我到目前为止所做的:

     var FeatureToAdd = _featureRepository.GetFeatures().FirstOrDefault(x => x.Id == 2);          
    
            // Initialize the REST API. You can specify a web service version if needed in the constructor.
            RallyRestApi restApi = GetRallyRestApi();
    
            //Create an item
            DynamicJsonObject toCreate = new DynamicJsonObject();
            toCreate["Name"] = FeatureToAdd.Name;
            toCreate["Description"] = FeatureToAdd.Description;
    
            // important to which this belongs, but I no ID I ever use works
            //toCreate["Workspace"] = "/workspace/" + WebConfigurationManager.AppSettings["RallyAPIWorkspaceID"];
            //toCreate["Project"] = "/project/XXXXX";
            //toCreate["Iteration"] = "/iteration/XXXXXX";
    
            // create feature - feature is under PortfolioItem
            CreateResult createFeatureResult = restApi.Create("PortfolioItem/Feature", toCreate);
    
            // scrape ID off the end of the reference
            var pureId = createFeatureResult.Reference.Substring(createFeatureResult.Reference.LastIndexOf('/') + 1);
    
            // add UserStories
            foreach (UserStory u in FeatureToAdd.UserStories)
            {
                toCreate = new DynamicJsonObject();
                toCreate["Name"] =u.Name;
                toCreate["Description"] = u.Description;
                toCreate["WorkProduct"] = "PortfolioItem/Feature/" + pureId;
                //toCreate["WorkProduct"] = createFeatureResult.Reference;<- tried this too
    
                // hierarchicalrequirement = UserStory
                CreateResult createUserStoryResult = restApi.Create("hierarchicalrequirement", toCreate);
            }
    

    运行它会创建两者,但不会发生任何关联。我收到警告:

    Ignored JSON element hierarchicalrequirement.WorkProduct during processing of this request.
    

    为什么随意忽略这个?...

1 个答案:

答案 0 :(得分:1)

它忽略了WorkProduct,因为WorkProduct不是HierarchicalRequirement上的有效字段。您要指定以设置故事的功能父级的字段称为PortfolioItem。

toCreate["PortfolioItem"] = Ref.GetRelativeRef(createFeatureResult.Reference);

此外,对象关系在WSAPI中指定为refs(/ type / id),因此您可以直接从createFeatureResult传入引用。

很抱歉,您发现api令人沮丧。它肯定有一些奇怪的黑暗角落但是一旦你使用它并感受到各种域对象是如何相关的,我认为你会发现它非常强大和一致。