Click here to Skip to main content
15,887,344 members
Articles / Programming Languages / C#
Tip/Trick

Rallydev - Automate Task creation using Rally REST API

Rate me:
Please Sign up or sign in to vote.
4.90/5 (3 votes)
26 Jan 2015CPOL3 min read 34K   638   3   1
This article is about the simple tool I have created to automate creation of Tasks for Userstories in Rallydev.

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.

Introduction

We are using Rallydev for some time now as our agile project management platform. It helps us manage our Releases, Iterations, Stories and Defects. I developed this tool for adding repetitive tasks for each of the stories based on predefined templates. One can also add or edit the tasks once loaded in the tool. This tool helped us save some time in sprint planning meetings.

Background

There are different ways to automate or improve adding multiple task for userstories:

  • Use the template story for creating the Story and tasks
  • Use excel import for creating tasks
  • Use Rally REST API Toolkit and write your own code to create these tasks.

After trying all the three ways, my personal preference is Option 3.

 

Image 1

Features

Following are the features of this tool:

 

  1. Create tasks for the given User Story ID
  2. Tasks can be added with Owners and Planned Estimates
  3. Modify an existing tasks template
  4. Add new tasks template
  5. Add, Edit and Remove tasks before saving to Rallydev

Modifying existing tasks template

List of tasks for any of the pre-defined or existing templates can be modified from the app config file.

Step 1: Open the configuration files and find DefectTemplate setting usder settings.

Step 2: You can add or remove the string entries in this list,

Step 3: Save the config file and restart the application.

<applicationSettings>
    <Vivek.Rallydev.Helper.Properties.Settings>
        <setting name="DefectTemplate" serializeAs="Xml">
            <value>
                <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                    <string>Design Discussion</string>
                    <string>Unit Testcase Documentation</string>
                    <string>Unit Testcase Review</string>
                    <string>Coding</string>
                    <string>Unit Testing</string>
                    <string>Code Review Level</string>
                    <string>Verification</string>
                </ArrayOfString>
            </value>
        </setting>

Adding new task template

Step 1: Add string entry for the new templates in the Templates section as below:

            <setting name="Templates" serializeAs="Xml">
                <value>
                    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <string>DefectTemplate</string>
                        <string>New Template</string>
                    </ArrayOfString>
                </value>
            </setting>

Step 2 :Add new settings with the name as "New Template". Below is the sample for adding 3 tasks.

<setting name="New Template" serializeAs="Xml">
    <value>
        <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <string>Task 1</string>
            <string>Task 2</string>
            <string>Task 3</string>
        </ArrayOfString>
    </value>
</setting>

Step 3 : The "New Template" will be now available in the Template dropdown

Using Rally REST API

Rally REST API allows us to perform queries and CRUD operations. For generating tasks in rally for a given userstory follow the steps below:

 

Step 1 : User Credentials to login to Rallydev

While creating the Rally REST API use the username and password that is used for logging into Rallydev.

 

Image 2

 

C#
RestApi = new RallyRestApi(user, password, "https://rally1.rallydev.com", "v2.0");

 

Step 2 : Workspace Reference

Next step is to generate the reference to the default workspace under which you intend to create all the tasks for the userstory. For all the subsequent create requests, we need to use the workspace references.

C#
Request workspactRequest = new Request("Workspace");
workspactRequest.Query = new Query("");
QueryResult workspaceResults = RestApi.Query(workspactRequest);

var workspace = workspaceResults.Results.FirstOrDefault();

WorksspaceRef = workspace._ref;

return WorksspaceRef;

Step 3 : Retrieve users in the Workspace

As part of creating the tasks, one of the obvious step is to set owners for each tasks. We need the list of users assigned to the current workspace. It's important to keep track of the user ref. which will be sent as part of the request marking the user as owner of the task.

C#
List<RallyUser> users = new List<RallyUser>();

Request userRequest = new Request("user");
userRequest.Query = new Query("");
userRequest.Limit = 10000;
QueryResult userResults = RestApi.Query(userRequest);

foreach (var item in userResults.Results)
{
    if (!item.Disabled)
        users.Add(new RallyUser() { UserName = item.UserName, UserRef = item._ref });
}

users.Sort(
     delegate(RallyUser first, RallyUser second)
     {
         return first.UserName.CompareTo(second.UserName);
     });
return users;

Step 4 : Userstory Reference

To create the tasks under a user story it's important to mark the task with the corresponding userstory reference. Here is how you get userstory ref based on the exact match of User Story ID.

C#
string storyRef = string.Empty;
Request storyRequest = new Request("HierarchicalRequirement");
storyRequest.Query = new Query("FormattedID", Query.Operator.Equals, req.StoryId);

QueryResult result = RestApi.Query(storyRequest);
foreach (var item in result.Results)
{
    storyRef = item["_ref"].ToString();
}
return storyRef;

Step 5 : Create Task

Finally create the tasks with the required fields initialized. If you have custom fields created at task level, you can initialize them as well. The reference fields are initialized with the value from _ref property of the corresponding object. As an example the Owner field is initialized with reference from the user object. Similarly WorkProduct is initialized with reference of the user story.

C#
DynamicJsonObject toCreate = new DynamicJsonObject();
toCreate["Name"] = item.Name;
toCreate["Estimate"] = item.Estimate;
toCreate["Owner"] = item.RallyUser.UserRef;

if (req.shouldUpdateActuals)
{
    toCreate["Actuals"] = item.Estimate;
}

toCreate["ToDo"] = item.Estimate;
toCreate["WorkProduct"] = storyRef;

CreateResult createResult = RestApi.Create(workspaceRef, "task", toCreate);
return createResult;

Points of Interest

Creating tasks and/or userstories using the above mentioned fields may fail in case you have any mandatory custom fields added in the configuration. It's not difficult to add additional details to the request.

// CustomField1 is the name of custom mandatory field.
toCreate["CustomField1"] = value;

For further help on Rally REST API refer to https://help.rallydev.com/for-developers

Further enhancements

  • Provide lookup for the stories in the current iteration..
  • Support for custom fields for tasks.

History

This is the initial version of the article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThanks Pin
Nelek27-Jan-15 10:45
protectorNelek27-Jan-15 10:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.