Page 1 of 1

ScriptCall Server Code Response

Posted: Thu Sep 11, 2014 3:35 pm
by anton6984647

I'm calling a script from another script server-side

call:
var res = ScriptCall.call("123", {"user_id":33}, "body text", "text/plain");

(this script 123 gives the response {"urlpic":"test"} when tested independently)

What code do I use to get this in the response of the original script?

Right now I'm trying to use
otheruserpic=res.body;
but this gives an incorrect output to what I want: {"otheruserpicurl":"{\"urlpic\"":\""test\""}""}
I just need {""otheruserpicurl"":""test""}"


ScriptCall Server Code Response

Posted: Thu Sep 11, 2014 5:58 pm
by Kateryna Grynko

Hi Anton,

Please use the following code:preotheruserpic = res.object().urlpic;/preInstead of:preotheruserpic=res.body;/pre


ScriptCall Server Code Response

Posted: Thu Sep 11, 2014 6:37 pm
by anton6984647

ok, I have this

var res = ScriptCall.call("123", {"user_id":seconduserclient, "SSTokenclt":SSTokenclient}, "body text", "text/plain");
var otheruserpic=res.object().urlpic;

this gives "message: Object #div class="video-container"object has no method 'object'
code: undefined" Any suggestions?/object


ScriptCall Server Code Response

Posted: Fri Sep 12, 2014 8:02 am
by Evgene Karachevtsev

Hello Anton,

A string comes to res.body. If you need to get an object, use JSON.parse
prevar obj = JSON.parse(res.body);/pre
Now you can get the value urlpic from the object obj
preobj.urlpic/pre


ScriptCall Server Code Response

Posted: Fri Sep 12, 2014 12:31 pm
by anton6984647

Great! Thanks for the explanation as well.


ScriptCall Server Code Response

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

How do i get the id or alias name of a server code script?


ScriptCall Server Code Response

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

Hi Girish,

You can get script id from url to this script.

See details: http://prntscr.com/52h6rh/direct

Regards.


ScriptCall Server Code Response

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

Thanks. This is also available under "rest information". Now my question is, will the request header be passed as well to the called script? It doesn't work for me when I call a script, say A, that contains the line request.user._id.


ScriptCall Server Code Response

Posted: Mon Nov 03, 2014 11:45 pm
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.