Rally Software

Expand all | Collapse all

Rally api .net toolkit v 3.2.1 connectivity and Timespent

  • 1.  Rally api .net toolkit v 3.2.1 connectivity and Timespent

    Posted 03-07-2018 11:03 AM

    I'm trying to use 3.2.1/3.1.1 connecting below and I get a bad gateway error. 3.0.1 works. This is for a .net c# 4.5 application targeting 2016.2.2 rally version.

    public static RallyRestApi getRestApi
    {
    //get { return _restApi;}
    get {

    RallyRestApi _restApi = new RallyRestApi(webServiceVersion: ReadAppSettingsValues("RallyURLVersion"));
    _restApi.Authenticate(ReadAppSettingsValues("RallyUserName"), ReadAppSettingsValues("RallyPassword"), ReadAppSettingsValues("RallyURL"),null,false);
    return _restApi;
    }
    }

     

    Also I'm trying to get the Timespent field but am getting a null value for that even though I know their is time associated with the Task.

    Request taskRequest = new Request(resultChild["Tasks"]);
    QueryResult TaskQueryResult = restApi.Query(taskRequest);
    foreach (var items in TaskQueryResult.Results)
    //foreach (var items in uTasks)
    {
    DataRow dtrow2;
    dtrow2 = dt.NewRow();
    dtrow2["TaskID"]=items["FormattedID"];
    dtrow2["Task Name"] = items["Name"];
    dtrow2["Task-Est"] = items["Estimate"];
    dtrow2["Task-ToDo"] = items["ToDo"];
    decimal ts = 0;
    ts = ts + items["TimeSpent"];

    }

     

    any help would be appreciated.



  • 2.  Re: Rally api .net toolkit v 3.2.1 connectivity and Timespent

    Posted 03-16-2018 07:09 AM

    JonathanTorres1355981,

     

    I know you have another question open for the connection issue, but I wanted to check on the TimeSpent question you had above.  Are you doing anything with the decimal 'ts' after you add the items["TimeSpent'] to it?  You declare it, set it to 0, add to it, but in your foreach loop, it does not get put into the row or anything else I can see.

     

    The code should work to get TimeSpent, I have tested what you have above, only with writing out the information to the console and not using the DataRow and not adding to the ts variable, but I get TimeSpent for each Task or 0.0 if there is nothing entered.

     

    Michael



  • 3.  Re: Rally api .net toolkit v 3.2.1 connectivity and Timespent

    Posted 03-16-2018 10:51 AM

    Yes after fixing the connection issue(Thanks for that). I forgot to include that I put the vairable into the datatable as such

      dtrow2["Task-Spent"] = ts;

     

    But like you items["TimeSpent"] is always 0.0 even though I know I have time in there since I enter that in the Timesheet section under the My Home tab and enter time into two tasks I have set up for this iteration. So I'm not sure how your suppose to read that since I find no more information on that. CA support says they can read that.

    Thanks,

    JT



  • 4.  Re: Rally api .net toolkit v 3.2.1 connectivity and Timespent

    Posted 03-16-2018 11:33 AM

    Jonathan,

     

    Hmm, OK.  Here is the code I tested:

     

    Request storyRequest = new Request("HierarchicalRequirement");
    storyRequest.Query = new Query("FormattedID", Query.Operator.Equals, "S1");
    QueryResult StoryResult = restApi.Query(storyRequest);
    foreach (var resultChild in StoryResult.Results)
    {
        Request taskRequest = new Request(resultChild["Tasks"]);
        QueryResult TaskQueryResult = restApi.Query(taskRequest);
        foreach (var items in TaskQueryResult.Results)
        {
           Console.WriteLine("TIME SPENT: " + items["TimeSpent"]);
        }
    }

     

    And the results:

     

    TIME SPENT: 13.0
    TIME SPENT: 8.0
    TIME SPENT: 0.0

     

    And from Agile Central:

     

    Time Spent

     

    The only other things I can think of:

    Are you using v2.0 of the Web Services?  TimeSpent is not available in the previous versions.

    Are you in the same Workspace with your code as you are when you enter time in the GUI?

    The placement of where you declare and set ts = 0 is messing things up somehow.  If you just write TimeSpent to the console, is anything available?

     

    One other thing you can try is listing the Tasks via the Web Services, just to see what is what.  I specifically set it to fetch TimeSpent.

     

    https://<YOUR_ON_PREM_SERVER>/slm/webservice/v2.0/task?workspace=https://<YOUR_ON_PREM_SERVER>/slm/webservice/v2.0/workspace/<WORKSPACE_OID>&fetch=TimeSpent&start=1&pagesize=200&pretty=true

     

    Other than that, I am sure glad you are able to connect now with the newer versions!

     

    Michael



  • 5.  Re: Rally api .net toolkit v 3.2.1 connectivity and Timespent

    Posted 03-16-2018 12:06 PM

    Here is my code and yes it should be in the same Namespace:

    User enters a value to look up which is the strVal

    try
    {
    Request request = new Request("hierarchicalrequirement");
    request.Fetch = new List<string>()
    {
    "Name",
    "FormattedID",
    "Iteration",
    "PlanEstimate",
    "Release",
    "ScheduleState",
    "TaskEstimateTotal",
    "TaskRemainingTotal",
    "c_SR",
    "Children",
    "Tasks",
    "Owner",
    "c_Complexity",
    "c_Application",
    "c_AppPts",
    "Project",
    "c_MilePts",
    "c_NASAAcceptedDate",
    "ObjectID",
    "Actuals",
    "Estimate",
    "ToDo",
    "TimeSpent"
    };
    request.Query = new Query("c_SR", Query.Operator.Equals, strVal.Trim())
    .Or(new Query("c_SR", Query.Operator.Contains,strVal.Trim()));
    request.Start = firstrecord;
    request.Workspace = null;
    request.PageSize = 200;
    request.Limit = 100000;
    request.Order = "FormattedID";
    RallyRestApi restApi = Common.getRestApi;
    Rally.RestApi.Response.QueryResult qr = restApi.Query(request);
    totalrecords = qr.TotalResultCount;
    if (totalrecords > 0)
    {
       dt = CreateDataTable();
       foreach (var result in qr.Results)
       {
    //Get UserSTory INfo
    strFormatttedID = result["FormattedID"];
    DataRow dtrow;
    dtrow = dt.NewRow();
    dtrow["UserStoryID"] = strFormatttedID;
    dtrow["SR"] = result["c_SR"];
    dtrow["Story Name"] = result["Name"];
    dtrow["Application"] = result["c_Application"];
    //dtrow["App Points"] = result["c_AppPts"];
    dtrow["Complexity"] = result["c_Complexity"];
    dtrow["ObjectType"] = "U";
    dt.Rows.Add(dtrow);
    //Get MilestoneInfo and Task
    var children = result["Children"];
    var chCount = children.Count;
    if (chCount> 0) //if no children then it's a milestone
    {
    Request childRequest = new Request(result["Children"]);
    QueryResult childQueryResult = restApi.Query(childRequest);
    foreach (var resultChild in childQueryResult.Results)
    //foreach (var resultChild in children)
    {
    DataRow dtrow1;
    dtrow1 = dt.NewRow();
    dtrow1["MileStone ID"] = resultChild["FormattedID"];
    dtrow1["MileStone Name"] = resultChild["Name"];
    if (resultChild["Project"] != null)
    {
    var proj = result["Project"];
    String projref = proj["_ref"];
    var projFetch= restApi.GetByReference(projref, "Name");
    dtrow1["LOB"] = projFetch["Name"];
    }
    else {dtrow1["LOB"] = "";}

     

    dtrow1["NASA Accepted Date"] = (Common.CheckDate(result["c_NASAAcceptedDate"]) == DateTime.MinValue ? " " : String.Format("{0:MM/dd/yyyy hh:mm:ss}", Common.CheckDate(result["c_NASAAcceptedDate"])));
    if (resultChild["Iteration"] != null)
    {
    var iteration = resultChild["Iteration"];
    String iterationref = iteration["_ref"];
    var iterationFetch = restApi.GetByReference(iterationref, "Name");
    dtrow1["Iteration"] = iterationFetch["_refObjectName"];

    }
    else
    {
    dtrow1["Iteration"] = "";
    }
    if (resultChild["Release"] != null)
    {
    var release = resultChild["Release"];
    String releaseref = release["_ref"];
    var releaseFetch = restApi.GetByReference(releaseref, "Name");
    dtrow1["Release"] = releaseFetch["_refObjectName"];

    }
    else
    {
    dtrow1["Release"] = "";
    }
    dtrow1["State"] = resultChild["ScheduleState"];
    dtrow1["PlanEst"] = resultChild["PlanEstimate"];
    dtrow1["TaskEst"] = resultChild["TaskEstimateTotal"];
    dtrow1["ToDo"] = resultChild["TaskRemainingTotal"];
    dtrow1["ObjectType"] = "M";

    var uTasks = resultChild["Tasks"];
    dtrow1["TaskCount"] = uTasks.Count;
    dt.Rows.Add(dtrow1);
    if (uTasks.Count > 0)
    {
    Request taskRequest = new Request(resultChild["Tasks"]);
    QueryResult TaskQueryResult = restApi.Query(taskRequest);
    foreach (var items in TaskQueryResult.Results)
    {
    DataRow dtrow2;
    dtrow2 = dt.NewRow();
    dtrow2["TaskID"]=items["FormattedID"];
    dtrow2["Task Name"] = items["Name"];
    dtrow2["Task-Est"] = items["Estimate"];
    dtrow2["Task-ToDo"] = items["ToDo"];
    decimal ts = 0;
    ts = ts + items["TimeSpent"];
    dtrow2["Task-Spent"] = ts;
    if (items["Owner"] != null)
    {
    var owner = items["Owner"];
    String ownerref = owner["_ref"];
    var ownerFetch = restApi.GetByReference(ownerref, "Name");
    string strTemp = ownerFetch["_refObjectName"];
    dtrow2["Owner"] = strTemp.Replace(",", " ");
    }
    else { dtrow2["Owner"] = ""; }
    dtrow2["ObjectType"] = "T";
    dt.Rows.Add(dtrow2);
    }
    }

    }

    }

    }

    Then I get all the information except for Timespent which is 0.0

     

    I do see the Timespent within that rally application like your picture(sorry can't figure out how to paste one into here)

     

    For webservice not sure how to get  <WORKSPACE_OID> but I see the time spent when I use the webservice on the on one of the tasks

    https://xxxxx/slm/webservice/v2.0/task/89601445 

     

    Thanks,

    JT



  • 6.  Re: Rally api .net toolkit v 3.2.1 connectivity and Timespent

    Posted 03-16-2018 01:42 PM

    OK, one thing to try is this, just to ensure you are indeed in the same Workspace for all your requests.  From your Task query, modify it a bit to weed out the extra pieces so it looks like this:

     

    https://xxxxx/slm/webservice/v2.0/task/89601445?fetch=workspace&pretty=true

     

    Then notice in the response the Workspace section and add the last section of the _ref portion to your requests to ensure you are in the same Workspace for all of them.  So for any request you do, add the following line:

     

    ***.Workspace = "workspace/***";

    So, for example you have one query at the start:

     

    request.Workspace = null;

     

    update that one to be:

    request.Workspace = "workspace/***";

     

    as well as the rest:

     

    childRequest.Workspace = "workspace/***";

    taskRequest .Workspace = "workspace/***";

     

    Does that make any difference?  If not, it may be worth a quick call/WebEx with Support on your support case to see if anything jumps out.

     

    Michael



  • 7.  Re: Rally api .net toolkit v 3.2.1 connectivity and Timespent

    Posted 03-16-2018 02:03 PM

    Michael,

    I was looking at this part as the only difference but

    I added

          request.Workspace = "workspace/PCMS Workspace";

    and

          request.Workspace = "PCMS Workspace";

     

    But with both when I run the query I get no results. I then googled and saw you have to put the number so like:

       request.Workspace = "/workspace/5103";

     

    I put this on childrequest and task as well. In all three instances I now get the record but again TimeSpent is 0.0

    I have a call into CA support so hopefully they can figure out what is going on.

     

    For 3.2.1 I still use <add key="RallyURLVersion" value="v2.0"/> correct?

     

    Could it be the user doesn't have access to the Timespent field?

     

    Do I have to specify a time frame or iteration for it to grab this information?

     

    I'm at a loss.