
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:11 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 10:14 AM - edited 07-05-2023 10:20 AM
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
Vicks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:22 AM
Why do you want to call a client callable script inlcude from a Scripted rest resource and why not use server side script include?
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:24 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 11:35 AM - edited 07-03-2023 01:18 PM
Ah! So instead of using ga.getXMLAnswer(function(answer) to get the response. I should be using?
var answer = ga.execute();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2023 01:20 PM
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();