Return value from a call back function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 06:27 AM
Hi All,
I have a client script that use GlideAjax.
I want to return a value from the call back function, does anyone know how to implement this?
my script:
function funcationName (number) {
var ga = new glideAjax('ScriptName');
ga.addParam('sysparm_name', 'function_name');
ga.addParam('sysparm_number', number);
return gs.getXMLAnswer(callBackFunction);
}
function callBackFunction(response){
response = JSON.parse(response);
return response[0] == 'name' ? true : false;
}
Thanks In Advance 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 06:32 AM - edited 08-09-2023 06:35 AM
Hi ,
It's good first you create an exmp. as per doc.
Use function like
var ga = new GlideAjax('HelloWorld'); // HelloWorld is the script include class
ga.addParam('sysparm_name','helloWorld'); // helloWorld is the script include method
ga.addParam('sysparm_user_name',"Bob"); // Set parameter sysparm_user_name to 'Bob'
ga.getXML(HelloWorldParse); /* Call HelloWorld.helloWorld() with the parameter sysparm_user_name set to 'Bob'
and use the callback function HelloWorldParse() to return the result when ready */
// the callback function for returning the result from the server-side code
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 06:48 AM
The returned value is okay but when I try to use it in the original function it's value is undefined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2023 06:57 AM
whatever further processing you want to do after the ajax do it in callback method only.
What's the point in adding that logic outside the callback?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2023 12:34 AM
I'm using more than one GlideAjax so I want to combine the logic in the main function