Rally API: documentation list of fields for portfolio items?

*爱你&永不变心* 提交于 2019-12-11 06:07:44

问题


I am using the Rally API (http://developer.help.rallydev.com/ruby-toolkit-rally-rest-api-json) via Ruby. I'd like to query Portfolio items for their attributes (fields?). I have working code, e.g. this works properly (although it seems to display the name, not the ID -- I was expecting something like 'T30' but this displays 'This is the name of my initiative'):

pi_query.order = "FormattedID Asc"

By trial and error, I also see that

pi_query.order = "Name Asc"

works too. My question: what values can I use here? I've looked for hours. Name, FormattedID, and Description work; Parent does not. I can't find a reference doc.

(I'm trying to write a custom report that'll display Portfolio items is a more readable way -- Themes, Initiatives, and Features displayed in some sort of nested fashion that I can print. The Portfolio Hierarchy app in Rally doesn't offer a printable view, so I was hoping to write a quick script for it. I don't need much, mainly the name, and whether the thing is a theme, initiative, or feature. Something like this:)

T30 My first theme
    I65 The first initiative
        F44 The first feature under that
        F45 Another feature
    I66 Another initiative
T31 My second theme
    I67 Yet another initiative

回答1:


I found it. Here is the correct link to the documentation:

https://rally1.rallydev.com/slm/doc/webservice/

If you click on 'AllowedAttributeValue' on the left, you'll get a list of attributes. Hit Ctrl-F and search for 'portfolio'. When you get down to the main header titled 'Portfolio Item (non-creatable type)', there's a checkbox for 'fetch full objects' and 'beautified JSON output'. Check both, then hit the 'Query' button just below. You'll get an object model in a new window.

From this new window, you can see all of the valid attributes. For example, search for 'Parent' and you can see the valid values for the Parent hash. One of those keys is _refObjectName, which gives you the name of the parent node.

Here is a working example, which queries for initiatives and displays their name and their parent's name.

require 'rally_api'

config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "REPLACE"
config[:password] = "REPLACE"
config[:workspace] = "REPLACE"
config[:project] = "REPLACE"
@rally = RallyAPI::RallyRestJson.new(config)

pi_query = RallyAPI::RallyQuery.new()
pi_query.type = "portfolioitem/initiative"
pi_query.fetch = "Name,FormattedID,Description,PortfolioItemTypeName,Parent"
pi_query.project_scope_up = true
pi_query.project_scope_down = true
pi_query.order = "FormattedID Asc"
pi_results = @rally.find(pi_query)

pi_results.each do |result|
   parent_name = (result.Parent == nil)? "" : "has parent \"" + result.Parent["_refObjectName"] + "\""
   puts result.FormattedID + " " + result.Name + " "  + parent_name
end



回答2:


Here's a more complete version that displays themes, their initiatives, and their features as indented output. There is likely a more efficient way to do the output, but this approach does generate the correct output against my project.

require 'rally_api'

config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "REPLACE"
config[:password] = "REPLACE"
config[:workspace] = "REPLACE"
config[:project] = "REPLACE"
@rally = RallyAPI::RallyRestJson.new(config)

pi_query = RallyAPI::RallyQuery.new()
pi_query.project_scope_up = false
pi_query.project_scope_down = true
pi_query.order = "FormattedID Asc"

# Themes

pi_query.type = "portfolioitem/theme"
pi_query.fetch = "Name,FormattedID"
pi_results = @rally.find(pi_query)

themes = []
pi_results.each { |theme| themes << [ theme.FormattedID, theme.Name ] }

# Initiatives

pi_query.type = "portfolioitem/initiative"
pi_query.fetch = "Name,FormattedID,Parent"
pi_results = @rally.find(pi_query)

initiatives = []
pi_results.each do |initiative|
  parent_name = (initiative.Parent == nil)? "" : initiative.Parent["_refObjectName"]
  initiatives << [ initiative.FormattedID, initiative.Name, parent_name]
end

# Features

pi_query.type = "portfolioitem/feature"
pi_query.fetch = "Name,FormattedID,Parent"
pi_results = @rally.find(pi_query)

features = []
pi_results.each do |feature|
   parent_name = (feature.Parent == nil)? "" : feature.Parent["_refObjectName"]
   features << [ feature.FormattedID, feature.Name, parent_name]
end

# Output

themes.each do |theme|
  puts theme[0] + " " + theme[1]
  initiatives.each do |initiative|
    if (initiative[2] == theme[1])
      puts "    " + initiative[0] + " " + initiative[1]
      features.each do |feature|
        if (feature[2] == initiative[1])
           puts "        " + feature[0] + " " + feature[1]
        end
      end
    end
  end
end


来源:https://stackoverflow.com/questions/16869602/rally-api-documentation-list-of-fields-for-portfolio-items

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!