我有一個從回看API獲取數據的應用程序。我在數據中獲得User ObjectID,但是我希望獲取用戶的DisplayName而不是ObjectID。拉力賽回顧API不允許水合用戶字段,所以在加載回顧API數據時我不能擁有用戶名。 我試圖用用戶對象ID過濾器創建商店來獲取用戶名,但我沒有得到用戶的名稱,直到回顧API數據加載完成。到回顧API數據加載完成時,我的數據操作也完成了。所以在第一次加載後加載用戶名是沒有用的。我嘗試將Store的異步屬性設置爲false/true,但沒有成功。 任何方式來完成這與拉力SDK 2.0? 這裏是代碼塊 -如何在CA Agile Central(AKA Rally)自定義應用程序中使用其ObjectID獲取單個對象詳細信息?
//Lookback call
_getStoriesByUser: function (user_story_ids, user_oids, user_story_state, users) {
this.acceptedByTM = [];
var scheduleStates = [];
scheduleStates.push('Accepted');
scheduleStates.push('Released to Prod');
var deferred = Ext.create('Deft.Deferred');
var me = this;
console.time("FetchingLBData");
var snapshotStore = Ext.create('Rally.data.lookback.SnapshotStore', {
"context": this.getContext().getDataContext(),
"fetch": ["ScheduleState", "_User", "_PreviousValues.ScheduleState"],
"hydrate": ["ScheduleState"],
"find": {
"ObjectID": { "$in": user_story_ids },
//"_User": { "$in": user_oids },
"_TypeHierarchy": "HierarchicalRequirement",
"ScheduleState": { "$in": scheduleStates },
"_PreviousValues.ScheduleState": { "$ne": null },
"Children": null
},
"sort": { "_ValidFrom": -1 }
});
snapshotStore.load({
callback: function (records, operation) {
if (operation.wasSuccessful()) {
console.timeEnd("FetchingLBData");
me.logger.log("LB US Count >>", records.length, records)
var total_us_accepted_by_tm = 0;
var tmAcceptedUS = 0;
var nontmAcceptedUS = 0;
var tm_accepted = [];
Ext.Array.each(user_story_state, function (uss) {
Ext.Array.each(records, function (rec) {
if ((rec.get('ObjectID') == uss.ObjectID && rec.get('ScheduleState') == 'Accepted') && (uss.ScheduleState == 'Accepted' || uss.ScheduleState == 'Released to Prod')) {
total_us_accepted_by_tm += 1;
tm_accepted.push({ ObjectID: rec.get('ObjectID'), UserObjectID: rec.get('_User') });
var userName;
//userName = me._fetchUserName(rec.get('_User')).value;
me._fetchUserName(rec.get('_User')).then({
success: function (records) {
userName = records[0].get('DisplayName')
},
failure: function (error) {
console.log('Error in Execution:', error)
}
}).always(function() {
console.log('Waiting for Update!');
});
//userName = rec.get('_User').DisplayName;
console.log('Accepted By Name: ', userName);
me.acceptedByTM.push({ ObjectID: rec.get('ObjectID'), UserObjectID: userName });
return false;
}
});
});
deferred.resolve(me.acceptedByTM);
} else {
deferred.reject('Problem querying lookback');
}
},
scope: me
});
return deferred;
},
//Get User Details for a given user
_fetchUserName: function (userObjId) {
var me = this;
var userName;
var userDetails;
var deferred = Ext.create('Deft.Deferred');
me.logger.log("Fetching User Information for User >>", userObjId);
var userFilter = Ext.create('Rally.data.wsapi.Filter', {
property: 'ObjectID',
value: userObjId
});
userDetails = Ext.create('Rally.data.wsapi.Store', {
model: 'User',
fetch: ['ObjectID', 'DisplayName'],
filters: userFilter,
limit: 1,
pageSize: 1
});
userDetails.load({
scope: this,
callback: function (records, operation, success) {
console.log("Operation Status: ", operation.synchronous);
if (success) {
//userName = records[0].get('DisplayName');
deferred.resolve(records);
} else {
deferred.reject(Ext.String.format("Error getting {0} count for {1}: {2}", 'User', userFilter.toString(), operation.error.errors.join(',')));
}
}
});
return deferred.promise;
}
你能分享你到目前爲止的代碼?這樣做不應該太難。一旦你的回顧商店被加載,你只需要遍歷數據並從wsapi加載用戶。這聽起來像你已經有很多,也許只是需要一些幫助管理所有的異步代碼? –
凱爾你好,我已經在原始文章中包含了代碼。 – Lokesh
@KyleMorse,你有沒有找到任何解決方案?我嘗試通過在應用程序的加載中包含Deft.Promise.All將活動用戶和禁用用戶加載到本地變量中。但是,在完成回顧數據加載後,用戶會被加載。 – Lokesh