What is the Signature of getDocument(URL, function(result){}) and where is the JS API Doc

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){

  teamCount = teamListData.length
  
  if(teamCount > 0 ){
       teamData = _.first(teamListData);
       teamName = teamData.name;
       doc.teamName = teamName;
   }
	
});
doc.myTeam = teamName ;
doc.myTeamTest = "Test: " + doc.teamName;

In this sample exemple, the row result is:

  • teamName = Name of the team
  • myTeam = empty
  • myTeamTest = Test: Undefined

I think it’s probably possible to include something in the context to fix that, by I don’t have any documentation about the JS API.

It’s why I’m asking:

  • What is the complete signature of the “getDocument” function ?
  • Can I found the Javascript documentation anywhere online ?

Thanks for your help.

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:
api_result

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;

Daina / support@eazybi.com

Diana, hi!

getDocument with a callback should launch an async operation, right?

We call it and then immediately return teams array that is empty at the time.

How does it work?

Hi, this doesn’t really fix my problem related with the scope of the function inside the getDocument.

var user_team_rq_url = "/rest/tempo-teams/2/user/" + username + "/memberships";
var teams = [];
getDocument(user_team_rq_url, {ignoreErrors: [404]}, function(teamListData){

  if (teamListData) { 
_.each(teamListData, function(teamData){
  teams.push({
    user: doc.name,
    teamName: teamData.team.name,
    isMember: 1
    });
});
  } else {
teams.push({
    user: doc.name,
    teamName: 'None',
    isMember: 0
    });
  }
});

doc.teamslength = teams.length;

If I checked the value of doc.teamslength I got 0 on EazyBI, because the push is done out of the scope of the getDocument.

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

Ok, How could I sync using javascript on the context of EazyBI.

It’s not like semaphore ou mutex are available.

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.

So, how does it do it?

For your particular case you might want to use the sync version of getDocument like this:

var teamListData = getDocument(user_team_rq_url, {ignoreErrors: [404]})
…process teamListData as you want

Thanks a lot. It’s exactly the behavior I want.

I think it really need more documentation about the javascript function of EazyBI.

Definitely, try it out.
And please tell me if it works.

All we can do is guess and experiment and just a little bit of docs on this can help a lot.

It’s working very wheel.

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.

1 Like

Hi,

I get http://localhost:8080 as the jirabaseurl.

How can I change it?

Hi,
The issue with the host needs a more detailed checking, please, contact the support.

Kindly,
Janis, eazyBI support