Help with my nodejs scripting service

hi
if anyone could help me with my nodejs Script service
on Dreamfactory 2.2

imagine following script

var lodash = require(“/usr/local/lib/node_modules/lodash”);
var api = new mangopay({
clientId: ‘myID’,

clientPassword: 'mypass',
   baseUrl: 'https://api.sandbox.mangopay.com'

});

api.Users.create({

Tag: “tag”,

FirstName: “fname”,
LastName: “lname”,
Birthday: 1463496101,
Nationality: “FR”,
CountryOfResidence: ‘FR’,

Email: 'myemail@myemail.com',
    PersonType: "NATURAL",

}, function(myOtherUser) {
return myOtherUser // This doesnt display anything

}

return “test” // return test → so ok here

it seems that the return inside the myOtherUser function doesn’t display/return value
even with a return “thisisatest”

the only return that works is outside any function.
so how could i pass myOtherUser value outside the function ?

same script in a .js file run form a bash display return myOtherUser …

thanks

I think that the problem is because api.Users.create() is an asynchronous function, so return "test" is actually executed before return myOtherUser.

Additionally take into account that return myOtherUser is the return value of the anonymous function that is passed to api.Users.create(), not the return value of the script.

1 Like

@jeebee, To set script response from an async operation use the method below…

event.setResponse(content, statusCode, contentType)