GlideAjax - return a value from callBack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 04:52 AM
I have a script in a catalog item that calls a function
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
checkNameSpace();
}
the function is another Client script that runs onload and allows the function to be called - see below
Right now I am passing the variable strField to the callback and doing some processing there - which works, but it would be a lot easier for what I am doing to use some code like the below where I simply return a true/false and do something from the calling script.
(so this is a shared function and editing this for a number of target fields is quite simply bonkers when the calling script above, can get a true/false and do the work. It keeps the script below simple and quicker)
I am however stumped at how to get that true / false from the callBack
function onLoad() {
}
checkNameSpace = function() {
var strField = 'tenant_namespace';
g_form.hideFieldMsg(strField,true);
var strName = g_form.getValue(strField)+'-' +g_form.getValue('tenant_environment')+'';
if(strName.length < 6) {
return true;
}
var ga = new GlideAjax('ValidationsAjax');
ga.addParam('sysparm_name','checkNameSpace');
ga.addParam('sysparm_environment',g_form.getValue('tenant_environment')+'');
ga.addParam('sysparm_namespace',g_form.getValue(strField)+'');
ga.getXMLAnswer(function(response){processNS(response,strField);});
function processNS(response,strField) {
try {
var answer = response;
if(answer =='true' || answer == true) {
// Right now, I am doing some more work here on the strField - I want to remove
return true;
} else {
return false;
// Right now, I am doing some more work here on the strField - I want to remove
}
} catch(e) {
console.log('check ns error : ' + e);
}
}
};
Any ideas if it can be done. I have not found anything
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 09:40 AM
Just been trying and keep n getting a unhandled exception in GlideAjax - I'll leave for now and have another look when I get more time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 09:49 AM