sshah
sshah

Reputation: 45

Rally Rest Api C# ToolKit

I am trying to use the C# toolkit for RallyRest API. I want to display the number of user stories for each release, and the number of tasks by a team. The hierarchical requirement request doesn't return all the data. Moreover, how can I filter the data based on a particular release and the owner of the User story? Below is my code. Can you please suggest where I should look? I saw the API.

RallyRestApi restApi = new RallyRestApi(username, password, "https://rally1.rallydev.com", "1.40");

            bool projectScopingUp = false;
            bool projectScopingDown = true;
            try
            {
                Request storyRequest = new Request("HierarchicalRequirement");
                storyRequest.Workspace = workspaceRef;
                storyRequest.Project = projectRef;

                storyRequest.ProjectScopeUp = projectScopingUp;
                storyRequest.ProjectScopeDown = projectScopingDown;
                storyRequest.Fetch = new List<string>()
                {
                    "Name",
                    "FormattedID",
                    "Project",
                    "Release",
                    "ScheduleState",
                    "State",
                    "Owner",
                    "Tasks"
    };
QueryResult queryStoryResults = restApi.Query(storyRequest);
                int totalUS = 0;
                foreach (var s in queryStoryResults.Results)
                {
                    if (s["Release"] != null)
                    {
                        Release = s["Release"]["Name"];
                        string word = "July 2014";
                        if (Release.Equals(word))
                        {
                           string tempOwner = s["Owner"]["_refObjectName"];
                        if (tempOwner.Contains("development")
                        {


                    Owner = s["Owner"]["_refObjectName"];
                    paragraph.AddFormattedText("ID : " + Id + " Name : " + Name + "  Owner : " + Owner + "Release :" + Release + "Number of Tasks : " + count, TextFormat.NotBold);

                    }

                    }
                }
            }

Upvotes: 0

Views: 3292

Answers (1)

nickm
nickm

Reputation: 5966

Here is an example that filters stories by a particular release and story owner. It also gets the Tasks collection on each story and hydrates it with a separate request.

static void Main(string[] args)
        {
            int storyCount = 0;
            int taskCount = 0;
            RallyRestApi restApi;
            restApi = new RallyRestApi("[email protected]", "secret", "https://rally1.rallydev.com", "v2.0");

            String workspaceRef = "/workspace/1234";     //replace this OID with an OID of your workspace

            Request sRequest = new Request("HierarchicalRequirement");
            sRequest.Workspace = workspaceRef;
            sRequest.Fetch = new List<string>() { "FormattedID", "Name", "Tasks", "Release", "Project", "Owner" };
            sRequest.Query = new Query("Release.Name", Query.Operator.Equals, "r1").And(new Query("Owner", Query.Operator.Equals, "[email protected]"));
            QueryResult queryResults = restApi.Query(sRequest);

            foreach (var s in queryResults.Results)
            {
                Console.WriteLine("FormattedID: " + s["FormattedID"] + " Name: " + s["Name"] + " Release: " + s["Release"]._refObjectName + " Project: " + s["Project"]._refObjectName + " Owner: " + s["Owner"]._refObjectName);
                storyCount++;
                Request tasksRequest = new Request(s["Tasks"]);
                QueryResult queryTaskResult = restApi.Query(tasksRequest);
                foreach (var t in queryTaskResult.Results)
                {
                    Console.WriteLine("Task: " + t["FormattedID"] + " State: " + t["State"]);
                    taskCount++;
                }
            }
            Console.WriteLine(storyCount + " stories, "+  taskCount + " tasks ");
        }

I noticed you are using 1.40 of WS API which is no longer supported. If you have older code it has to be re-factored to work with v2.0. In v2.0 it is not possible to hydrate the collection in the same request. There are many examples on StackOverflow rally tag on this subject, e.g. here Download latest dll for the toolkit here.

Upvotes: 1

Related Questions