Javascript Support: within apigee, is passing a function as aparameter to another function supported

I'm porting existing js functions to apigee. One of the functions is constructed similar to what is shown below in the getRoles() which takes a function as a parameter

In the below function, when running on apigee nothing appears to be evaluated after var userX declaration. This function is skipped and the next is evaluated.

Is this a problem with the syntax or I need to refactor into seperate functions without nested declarations?

function build_my_stuff(config) {
  var userN = "xxxxx";
  var userP = "yyyyyy";
  var device = "rrrrrrr";
  var userX = "pppppT";
  getRoles(userN, config, function(titles) {
    var things = {
          xyz : "GUESS",
          tuv : userN,
          rty : userP,
          uio : device,
          roles : titles,
          attrs : { dev_id : device, user : userX }
        };
    dothis (things, config);
  });
}

Solved Solved
0 2 295
1 ACCEPTED SOLUTION

The syntax you are using looks fine.

But whether it operates the way you expect depends on what happens in getRoles().

Asynch JavaScript won't work in a JavaScript callout.

What is getRoles? The JS callout will not "wait" for the callback you pass to getRoles , to be called.

View solution in original post

2 REPLIES 2

The syntax you are using looks fine.

But whether it operates the way you expect depends on what happens in getRoles().

Asynch JavaScript won't work in a JavaScript callout.

What is getRoles? The JS callout will not "wait" for the callback you pass to getRoles , to be called.

Thanks, it was an asynch. call I will have to refactor to use httpclient.