如何使用 Rally Ruby API 访问自定义字段 [英] How to access a custom field using Rally Ruby API

查看:40
本文介绍了如何使用 Rally Ruby API 访问自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rally 工件上有一个自定义字段,在 WS API 文档中显示为 c_MyCustomField

There is a custom field on Rally artifact that shows in WS API document as c_MyCustomField

但它不打印:

results = @rally.find(query)

results.each do |d|
       puts "Name: #{d["Name"]}, FormattedID: #{d["FormattedID"]}, Owner: #{d["Owner"]["UserName"]}, MyCustomField: #{d["c_MyCustomField"]}"
       d.read
end

推荐答案

首先,检查是否正在获取字段:

First, check that the field is being fetched:

query.fetch = "c_MyCustomField"

接下来,如果使用 v2.0,则必须明确设置 WS API 的版本.

Next, a version of WS API has to be explicitly set if v2.0 is used.

c_ 前缀特定于 WS API 版本 v2.0.默认情况下,really_api 将使用先前版本的 WS API.如果您没有在代码中明确指定 WS API 版本,请参考之前版本的 WS API 中提到的自定义字段,不带 c_:

c_ prefix is specific to WS API version v2.0. By default rally_api is going to use a prior version of WS API. If you do not explicitly specify WS API version in your code, refer to the custom field as it is refered to in the prior versions of WS API, without c_:

results.each do |d|
    puts "MyCustomField: #{d["MyCustomField"]}"
    d.read
end

如果代码中设置了最新版本的WS API:

If the latest version of WS API is set in the code:

config[:version] = "v2.0"

那么自定义字段前面应该有 c_:

then the custom field should have c_ in front of it:

results.each do |d|
    puts "MyCustomField: #{d["c_MyCustomField"]}"
    d.read
end

这假设您正在使用 RallyRestTookitForRuby 和最新的 rally_api gem.

This assumes that you are using RallyRestTookitForRuby with the latest rally_api gem.

gem list -l

应该列出rally_api 0.9.20

should list rally_api 0.9.20

请注意,不再支持较旧的rally_rest_api.它也不适用于 WS API v2.0.

Note that the older rally_rest_api is no longer supported. It will also not work with v2.0 of WS API.

这是一个 ruby​​ 脚本示例:

Here is a ruby script example:

require 'rally_api'

#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "My Utility"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"

# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user@co.com"
config[:password] = "secret"
config[:workspace] = "W1"
config[:project] = "P1"
config[:version] = "v2.0"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()

@rally = RallyAPI::RallyRestJson.new(config)

query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "c_MyCustomField"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111.js" } #optional
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" } #Team Group 1 from Product 2
query.page_size = 200 #optional - default is 200
query.limit = 1000 #optional - default is 99999
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = "(Owner.UserName = someuser@co.com)"

results = @rally.find(query)

results.each do |d|
    puts "MyCustomField: #{d["c_MyCustomField"]}"
    d.read
end

这篇关于如何使用 Rally Ruby API 访问自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆