質問

入力した時間に関係なく、2つの特定の日付の間のすべての時間エントリが欲しいのです。時間入力項目を照会する必要があり、その値の_ref値を別々の要求で取得する必要があります。

時間に到達するためのより効率的な方法はありますか? たぶんコードの例は?

役に立ちましたか?

解決

TimeEntryItemから始めてTimeEntryValuesを通過するか、またはその逆にトラバースするか、解決しようとしている問題に依存します。たとえば、時間を集計したい場合は、項目 - >値の方向を選択できます。

これは、ノードのテイクトリテキットで書かれた2つの例です。

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);
.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top