AnsweredAssumed Answered

How to add/update milestones in a feature using Rally Rest API & C#?

Question asked by a737d218903a07f04dc34026e5e38db2 on May 19, 2016
I have already Features created in the Rally. What I am doing is, I am searching an existing Feature with its name in Rally and want to update the milestone in this particular feature. Currently, there is no milestone added in this particular Feature. So, I want to add a milestone. If I see in Rally on the UI for a particular feature then I can see and select multiple values for Milestone combo box on the UI. But not able to add it by code using Rally Rest API and C#. Please help me here as I am not able to proceed further from last one week. My code is as under follows:-
public DynamicJsonObject UpdateFeaturesbyName(string fea, string bFun)
        {
            //getting list of Feature.
            Request feat = new Request("PortfolioItem/Feature");
            feat.Query = new Query("Name", Query.Operator.Equals, fea);
            QueryResult TCSResults = restApi.Query(feat);
            foreach (var res in TCSResults.Results)
            {
                var steps = res["Milestones"];
                Request tsteps = new Request(steps);
                QueryResult tstepsResults = restApi.Query(tsteps);
                foreach (var item in tstepsResults.Results)
                {

                }

                if (res.Name == fea)
                {
                    var targetFeature = TCSResults.Results.FirstOrDefault();

                    DynamicJsonObject toUpdate = new DynamicJsonObject();
                    //toUpdate["Milestones"] = "";
                    // CreateResult createResult = restApi.Create(steps._ref, toUpdate);
                    // String contentRef = steps._ref;
                    //String contentRef = createResult._ref;
                    string[] value = null;
                    string AccCri = string.Empty;

                    if (!string.IsNullOrWhiteSpace(bFun))
                    {
                        value = bFun.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                        foreach (string item in value)
                        {
                            //if (string.IsNullOrWhiteSpace(AccCri))
                            //    AccCri = item;
                            //else
                            //    AccCri = AccCri + "<br/>" + item;
                            if (!string.IsNullOrWhiteSpace(item))
                            {
                                //Query for Milestone.
                                Request ms = new Request("Milestone");
                                ms.Fetch = new List<string>() { "Name", "ObjectID" };
                                ms.Query = new Query("Name", Query.Operator.Equals, item);
                                QueryResult msResults = restApi.Query(ms);

                                var targetMLResult = msResults.Results.FirstOrDefault();
                                long MLOID = targetMLResult["ObjectID"];
                                
                                DynamicJsonObject tarML = restApi.GetByReference("Milestone", MLOID, "Name", "_ref", "DisplayColor");
                                DynamicJsonObject targetML = new DynamicJsonObject();
                                targetML["Name"] = tarML["Name"];
                                //targetML["_ref"] = tarML["_ref"];
                                targetML["_ref"] = "/milestone/" + Convert.ToString(MLOID);
                                targetML["DisplayColor"] = tarML["DisplayColor"];

                                //New way of doing.
                                ArrayList mlList = new ArrayList();
                                mlList.Add(targetML);
                                var existingMilestones = targetFeature["Milestones"];
                                //existingMilestones["_tagsNameArray"] = null;
                                existingMilestones["_tagsNameArray"] = mlList;
                                toUpdate["Milestones"] = existingMilestones;
                                OperationResult updateResult = restApi.Update(res["_ref"], toUpdate);
                                bool resp = updateResult.Success;


                                //Second way of doing.
                                //// Grab collection of existing Milestones.
                                //var existingMilestones = targetFeature["Milestones"];
                                //long targetOID = targetFeature["ObjectID"];
                                //// Milestones collection on object is expected to be a System.Collections.ArrayList.
                                //var targetMLArray = existingMilestones;
                                //var tagList2 = targetMLArray["_tagsNameArray"];
                                //tagList2.Add(targetML);//
                                ////targetMLArray.Add(targetML);
                                //targetMLArray["_tagsNameArray"] = tagList2;
                                //toUpdate["Milestones"] = targetMLArray;
                                //OperationResult updateResult = restApi.Update(res["_ref"], toUpdate);
                                //bool resp = updateResult.Success;

                            }
                        }

                    }

                    //toUpdate["c_AcceptanceCriteria"] = AccCri;
                    //OperationResult updateResult = restApi.Update(res._ref, toUpdate);
                }
            }

            var features = TCSResults.Results.Where(p => p.Name == fea).FirstOrDefault();
            var featuresref = features._ref;
            return features;
        }



 

Outcomes