2014-01-10 23 views
0

我希望在兩個特定日期之間的所有時間條目,而不管它們輸入的時間。我必須查詢時間輸入項目,然後獲取單獨請求中值的_ref值。如何使用Rally WS API提取時間表數據?

有沒有更有效的方法來達到小時? 也許是一段代碼示例?

回答

0

無論您選擇以TimeEntryItem開頭並遍歷TimeEntryValues,還是其他方式,都取決於您嘗試解決的問題。例如,如果您想彙總時間,則可以選擇項目 - >值方向。

下面是兩個例子寫有Rally REST tookit for Node

var rally = require('rally'), 
    queryUtils = rally.util.query, 
    restApi = rally({ 
     user: '[email protected]', 
     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: '[email protected]', 
     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); 
相關問題