Can't get Glide Ajax function to work in Scripted Rest Resource

peterscaramuzzo
Tera Expert

I have a script include that I want to call inside a Scripted REST Resource. However if I call the function using:

 

new GlideAjax('MyFunction')

 

I get syntax errors. So I have to change the call in the code to

 

new MyFunction();

 

This works, however I am now noticing that my call to getXMLAnswer never gets called. It never executes my gs.log command, that I placed inside that getXMLAnswer call. Is it not working because I need to call the function as

 

new GlideAjax('MyFunction')

 

to get that to work? If so, how do I get around that error that causes the whole script to fail when I call it in this way? 

 

1 ACCEPTED SOLUTION

Hi,

 

you might update your existing script include to add below lines in order to accept parameters from Server side scripting.

 

//Script include

 

 

var GetAssignmentGroup = Class.create();
GetAssignmentGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssignmentGroupCondition1: function(parm1,parm2 ) { // adding parameters in order to access values from server side scripting
var results = [];
if( !parm1 && !parm2 ){ // if parm1 and parm 2 are null then the script include is probably being called from client script; hence if statement
var parm1 = this.getParameter('sysparm_parm1');
var parm2 = this.getParameter('sysparm_parm2');
}
//evaluate parm1 and parm2 as you need it

 

 

 

//REST Script

 

 

// your code

var script_include_result = new GetAssignmentGroup().getAssignmentGroupCondition1("<parm1_value>","<parm2_value>")

// use above result as you need it

 

 

 

Hope this helps.

 

Regards,

Vicks

 

 

Regards,
Vicks

View solution in original post

12 REPLIES 12

Aman Kumar S
Kilo Patron

Why do you want to call a client callable script inlcude from a Scripted rest resource and why not use server side script include?

 

Best Regards
Aman Kumar

Fabian Kunzke
Kilo Sage
Kilo Sage

Hello,

 

A scripted REST resource uses a serverside script in the field "Resource Script". You can just call script includes and functions normally from there without the use of GlideAjax. In fact, GlideAjax should not work at all.

 

The resource script is usually used to parse the body of the REST call. This can be done by using the "response.body" object.

 

To learn more about scripted REST resources and how to use them, i highly recommend going through this developer guide.

 

Regards

Fabian

Ah! So instead of using  ga.getXMLAnswer(function(answer) to get the response. I should be using?

 

var answer = ga.execute();

 

 

I think I am getting closer but the value I get back is undefined for both the response and response body

 

var response = ga.execute();
var responseBody = response.getBody();