get value from call back function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 08:03 AM
Hi All,
I am using a glideajax call to script include to check for the class, now i need to return the answer from call back function.
So in the below script i need to get the value in check from call back function, without writing my next code in the call back function. But, i am not able to return the value as we cannot return from an asynchronous call inside a synchronous method.
var ga = new GlideAjax("XYZ");
ga.addParam("sysparm_name","getClass1");
ga.addParam("sysparm_CIName",g_form.getValue('cmdb_ci'));
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var check = false
var typeofRequest = serverResponse.responseXML.getElementsByTagName("Type");
var ciclass = typeofRequest[0].getAttribute('superclass1');
if(ciclass != 'BusSv Names')
{
check = true;
}
}
Please suggest on a simple way to get the value from callback function.
Thanks and regards,
Swamy
Workflow based requests and Change Requests -- pending for approval,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 10:26 AM
I'm not sure if this will help but first these are my assumptions:
1) This script is in a client script. I think that because I see the use of g_form.getValue()
2) Although the next part of your script is desired to be outside of the callback it sounds like it's still dependent upon the answer that's returned from the callback
In that scenario the script that is outside of the callback I would write within a function and call that function inside the call back.
var ga = new GlideAjax("XYZ");
ga.addParam("sysparm_name","getClass1");
ga.addParam("sysparm_CIName",g_form.getValue('cmdb_ci'));
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var check = false
var typeofRequest = serverResponse.responseXML.getElementsByTagName("Type");
var ciclass = typeofRequest[0].getAttribute('superclass1');
if(ciclass != 'BusSv Names')
{
check = true;
}
if(check){
outsideScript();
}
}
function outsideScript(){
// do my stuff here
}
Or you could get rid of "check" and just use your first condition statement. Or you could pass the check variable to the outside function.
...
outstideScript(check);
...
function outsideScript(check){
if(check == 'true'){
//do stuff here
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2016 10:28 AM
You can write your code in the callBack function itself.