I am working on a very large datasource to import Tempo data from a Jira Instance. I’m using the rest API of tempo-core, tempo-timesheet, tempo-teams and tempo budget.
Few of my source, need to do hierarchical request. It’s why I’m using “getDocument”. In the past, I had no problem, but I just found it’s impossible to call more than one time “getDocument” sequentially. If I’m doing it, I lost the access to the var (including the global one) in any action I’m doing after the “getDocument” call.
ex:
var jirabaseurl = “https://myjira.local”;
var username = doc.name;
var user_team_rq_url = jirabaseurl + “/rest/tempo-teams/2/user/” + username + “/memberships”;
var teamName = new String();
getDocument(user_team_rq_url, {ignoreErrors: [404]}, function(teamListData){
If I’m doing nested call of “getDocument”, I lost the possibility to return more than one row in one Call, because the return will be done in the getDocument and not in the main function.
You are using function getDocument correctly. You can omit jirabaseurl part in the user_team_rq_url, though. We pick up the same domain automatically.
The results of getDocument function depend on the API you are using. In this case, you can address team name with teamData.team.name.
Please check the results of this API for one user in my demo data:
If you would like to access all rows of nested call in mapping, you would like to create a new set here. Here is an example, of a new set teams with two values - username, team. You can add any other value there either from the initial data set (doc.XX) or from nested call results (teamListData[i].xx).
var username = doc.name;
var user_team_rq_url = "/rest/tempo-teams/2/user/" + username + "/memberships";
var teamName = new String();
var teams = [];
getDocument(user_team_rq_url, {ignoreErrors: [404]}, function(teamListData){
if (teamListData) {
for(var i = 0; i < teamListData.length; i++) {
doc.i = i;
var teamData = teamListData[i];
teams.push({
user: doc.name,
teamName: teamData.team.name
})
}
}
});
return teams;
Scope should have nothing to do with it, teams.length at the time of your assignment would be zero, because getDocument returns immediately, it’s async.
You have to wait some time before teams array is populated (the request should be made and processed).
Exactly my question - it’s not clear how the async stuff is handled in context of EazyBI.
In practice functions like getDocument should return something like a Promise object that you can use to append some handlers to it that would be executed once the Promise is resolved or just wait for it to be resolved.
EazyBI has some mechanism to wait for your teams array to be fully populated though.
If you do return teams; it will do that.
It took a little bit more time to process and I had to divise my process into more than one datasource to avoid Timeout (divide current timesheet and previous), but it’s really what I want. Also, the process I put in place to report the timesheet status of 7000 employees is only generated one time by day. So if it took 1 more minutes it’S not a blocker.