Page 1 of 1

How to Invoke another server code script from a server code script

Posted: Fri Oct 31, 2014 7:35 am
by girish

I have two server code scripts A and B. I want to invoke script A from script B by passing parameters and use the result set for further steps in script B. How do i do that?


How to Invoke another server code script from a server code script

Posted: Fri Oct 31, 2014 11:00 am
by Maryna Brodina

Hello!

You need to call it via XMLHttpRequest http://devcenter.appery.io/documentat...


How to Invoke another server code script from a server code script

Posted: Fri Oct 31, 2014 6:34 pm
by girish

When i am calling the script from another script, both of which are running at server end, why unnecessarily an XHR request to be made?

I was expecting something similar to http://devcenter.appery.io/documentat....

So, in this case, there are two ways to invoke, via an id to the script or by alias name. How do i get the id or alias name from servercode tab for my server side scripts?


How to Invoke another server code script from a server code script

Posted: Fri Oct 31, 2014 7:00 pm
by girish

ok, I managed to find out id and alias name of a server code script. Now, say for example, A and B are two scripts.

A:
...
var userId = request.user._id;
console.log(userId);
...

B:
...
var userId = request.user._id;
console.log(userId);
var res = ScriptCall.call("A_aliasName", {}, "body text", "text/plain");
...

Now, when I execute B, here it gets the user id from the request. Similarly, when A is executed separately, it gets the value of user id from the request. However, when A is invoked from B, it complaints that

"Cannot read property 'id' of null ( @ 2 : 25 ) - var userId = request.user.id;"

What am i missing?


How to Invoke another server code script from a server code script

Posted: Mon Nov 03, 2014 12:05 am
by Yurii Orishchuk

Hi Girish,

Here is a simple code to RUN other server script by ID. ID you can find in url to this script editor.

pre

var res = ScriptCall.call("dd49c8c9-be34-451e-86bf-7d51e1a8af06", {"key":"value"}, "body text", "text/plain")

console.log(JSON.stringify(res));

/pre

If you want to get response parameter in "A" script you should pass this parameter when invoke the script.

For your case it should be like:

pre

var res = ScriptCall.call("dd49c8c9-be34-451e-86bf-7d51e1a8af06", {"user": {"_id": "1235567"} }, "body text", "text/plain")

console.log(JSON.stringify(res));

/pre

In this way you can pass all parameter you need.

Regards.


How to Invoke another server code script from a server code script

Posted: Mon Nov 03, 2014 12:56 am
by girish

Yes, but the way I invoke differs, correct? When I invoke A directly, request.user.id is part of session request header. But when the same is invoked from B, this request header is not passed and hence request.user.id doesn't work. So how do we pass the request headers as well to the called script?


How to Invoke another server code script from a server code script

Posted: Tue Nov 04, 2014 12:38 am
by Yurii Orishchuk

Hi Girish,

Unfortunatly there is no ability to pass headers.

If you need it you can use XHR.send instead of "ScriptCall.call".

Regards.