2013-10-02 97 views
0

所以我必須用拉力此查詢:返回對象類型拉力

query_result = stuff.slm.find(:hierarchical_requirement, :project => project, :workspace => stuff.workspace, :project_scope_up => false, :project_scope_down => true){ equal :name, parent_name.strip } 

,然後我做的,

parent = query_result.results.first 

,我很好奇,想知道什麼樣的對象被分配到母公司。我不在Rally的例外列表中,因此無法運行該腳本。但是,我正在爲此腳本撰寫SSO集成並遇到一些問題。我覺得我的問題將被解決,如果我檢查「父」,因爲函數返回這個「父」。如果有人有任何關於此的信息,請分享。謝謝!

回答

0

分配了故事(HierarchicalRequirement)對象。下面打印使用Rally Ruby REST toolkit

代碼:

my_story: abc, FormattedID: US86, _ref:https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/12891971030 

@rally = RallyAPI::RallyRestJson.new(config) 
some_name = "abc" 
query = RallyAPI::RallyQuery.new() 
query.type = :story 
query.fetch = "FormattedID" 
query.query_string = "(Name = \"#{some_name}\")" 
results = @rally.find(query) 

my_story = results.first 
puts "my_story: #{my_story}, FormattedID: #{my_story["FormattedID"]}, _ref:#{my_story["_ref"]}" 

如果在你的代碼中你試圖找到一個基於FormattedID的用戶故事,這裏是一個例子。由於故事的父母是一個故事,因此我的腳本中使用「故事」而不是「父母」來清楚地說明它是否爲父母並不重要。在本例中,FormattedID是作爲命令行參數輸入的。注意我使用story = result.first,而不是story=result。下面是輸出的截圖:

enter image description here

require 'rally_api' 

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

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

unless ARGV.length == 1 
    puts "enter one argument, e.g. US123, with no spaces" 
    exit 
end 

story = nil 
story_id = ARGV[0] 
puts "find story by FormattedID: #{story_id}" 

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

query = RallyAPI::RallyQuery.new() 
query.type = :story 
query.fetch = "Name,FormattedID,ScheduleState" 
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/workspace/1111.js" } 
query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/v2.0/project/2222.js" } 
query.project_scope_up = true 
query.project_scope_down = true 

query.query_string = "(FormattedID = \"#{story_id}\")" 

result = @rally.find(query) 

if(result.length > 0) 
    puts "found the story" 
    story = result.first 
    puts "FormattedID: #{story["FormattedID"]}, Name: #{story["Name"]}, ScheduleState: #{story["ScheduleState"]}" 
else 
    puts "did not find a story with FormattedID #{story_id}" 
end 
puts story.class 
puts story.inspect 
+0

當我試圖從我的方法返回這個對象,我得到這個錯誤:{:錯誤=> [「不能從\解析對象引用」規定\「」],:warnings => [「API狀態已過時,並將於10/26/2013不支持」]} 我不確定您是否可以完全幫助我,因爲我沒有在此共享代碼,但我想很多人在使用Rally-Excel插件之前都會面臨這個錯誤。你能告訴我什麼可能是錯的嗎? –

+0

你在使用rally_api還是不支持的rally_rest_api?你可以試試我的代碼,看看它是否適合你?恐怕我沒有看到有關Excel插件和Ruby的問題。 – nickm

+0

您的代碼確實有效,但是我的預先存在的代碼不起作用,並且出現「Can not parse object reference」錯誤。我無法理解這個問題。你知道錯誤的含義嗎? –