我想要在两个特定日期之间的所有时间条目,无论它们输入的时间。我必须查询时间输入项,然后在单独的请求中获取值的_ref值。
有没有更有效的方式来达到时间? 也许是一段代码?
答案 0 :(得分:0)
您是选择以TimeEntryItem开始并遍历TimeEntryValues,还是反过来,取决于您尝试解决的问题。例如,如果您想要汇总时间,可以选择项目 - >价值观方向。
以下是使用Rally REST tookit for Node编写的两个示例:
var rally = require('rally'),
queryUtils = rally.util.query,
restApi = rally({
user: 'user@co.com',
pass: 'secret',
apiVersion: 'v2.0',
server: 'https://rally1.rallydev.com',
requestOptions: {
headers: {
'X-RallyIntegrationName': 'Timesheet data: from TEItem to TEValue',
'X-RallyIntegrationVendor': 'Rally',
'X-RallyIntegrationVersion': '1.0'
},
}
});
function getTimeEntryValues(result) {
for(var i = 0, length = result.Results.length; i < length; i++){
console.log(result.Results[i].Values._ref);
getValue(result.Results[i].Values._ref);
}
}
function getValue(ref){
restApi.query({
ref: ref,
fetch: ['Hours', 'DateVal']
},
function(error, result){
if(error) {
onError(error);
} else {
console.log('Success!', result)
}
});
}
function getTimeEntryItems(callback) {
var query = queryUtils.where('WeekStartDate', '>=','2014-01-01T00:00:00.000Z' );
query = query.and('WeekStartDate', '<=','2014-02-01T00:00:00.000Z' );
restApi.query({
type: 'TimeEntryItem',
start: 1,
limit: Infinity,
fetch: ['Values', 'TaskDisplayString', 'WorkProductDisplayString'],
scope: {
workspace: '/workspace/12352608129',
up: false,
down: false
},
query: query
}, function(error, result) {
if(error) {
onError(error);
} else {
callback(result);
}
});
}
function onSuccess(result) {
console.log('Success!', result);
}
function onError(errors) {
console.log('Failure!', errors);
}
getTimeEntryItems(getTimeEntryValues);
这是第二个在TimeEntryValues上查询然后在TimeEntryItems上查询的示例:
var rally = require('rally'),
queryUtils = rally.util.query,
restApi = rally({
user: 'user@co.com',
pass: 'secret',
apiVersion: 'v2.0',
server: 'https://rally1.rallydev.com',
requestOptions: {
headers: {
'X-RallyIntegrationName': 'Timesheet data node.js program',
'X-RallyIntegrationVendor': 'Rally',
'X-RallyIntegrationVersion': '1.0'
},
}
});
function getTimeEntryValues() {
var query = queryUtils.where('DateVal', '>=','2014-01-08T00:00:00.000Z' );
query = query.and('DateVal', '<=','2014-01-10T00:00:00.000Z' );
return restApi.query({
type: 'TimeEntryValues',
start: 1,
limit: Infinity,
fetch: ['TimeEntryItem', 'Hours'],
scope: {
workspace: '/workspace/12352608129',
up: false,
down: false
},
query: query
});
}
function getTimeEntryItems(result) {
var timeEntryItems = [];
for(var i = 0, length = result.Results.length; i < length; i++){
console.log(result.Results[i].TimeEntryItem._ref.split("/").pop());
timeEntryItems.push(result.Results[i].TimeEntryItem._ref.split("/").pop()); //get ObjectID from _ref, since _ref is not queriable
}
console.log('object ids of time entry items: ', timeEntryItems);
var query = queryUtils.where('ObjectID', '=',timeEntryItems[0]);
for (var i = 1, length = timeEntryItems.length; i < length; i++) {
query = query.or('ObjectID', '=',timeEntryItems[i]);
}
return restApi.query({
type: 'TimeEntryItem',
fetch: ['TaskDisplayString', 'WorkProductDisplayString', 'WeekStartDate'],
query: query,
});
}
function onSuccess(result) {
console.log('Success!', result);
}
function onError(errors) {
console.log('Failure!', errors);
}
getTimeEntryValues()
.then(getTimeEntryItems)
.then(onSuccess)
.fail(onError);