Async Ajax call to a script include with no return value

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2020 03:05 AM
Hi,
How can I call a script include function using GlideAjax which returns nothing (script include function update a record)??
Thanks,
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2020 03:13 AM
I assume via your client script you need to insert records in some table.
Do something like this
var ga = new GlideAjax('URSINAME');
ga.addParam('sysparm_name', 'YOUFUNCTION');
ga.addParam('sysparm_user_name', "urdatawhichwannasend");
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
console.log(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2020 03:43 AM
You don't need the callback function if you do not want to do anything client side.
So something like this will work:
var ga = new GlideAjax('script include name');
ga.addParam('sysparm_name', 'function name');
ga.addParam('sysparm_variable', your_variable);
ga.getXML();
however, might be good to include the callback function to display something to the user it was successful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2020 05:51 AM
Yes. One use case is when creating a scheduled job from script include.
https://www.servicenowguru.com/scripting/execute-scheduled-jobs-script/