Skip to content

Instantly share code, notes, and snippets.

@thisnameissoclever
Created October 10, 2022 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisnameissoclever/2f93a0a6e02793b7752af9e4260838bd to your computer and use it in GitHub Desktop.
Save thisnameissoclever/2f93a0a6e02793b7752af9e4260838bd to your computer and use it in GitHub Desktop.
ServiceNow Animated "Loading" field message during GlideAjax call
var gaSlowGlideAjaxCall = new GlideAjax('{some_glideajax_script_include');
//todo: Set the second argument to the method you want to execute from your GlideAjax Script Include
gaSlowGlideAjaxCall.addParam('sysparm_name', '{some_slow_glideajax_script_method');
//todo: Add whatever other GlideAjax parameters you need to add below, such as:
gaSlowGlideAjaxCall.addParam('record_sys_id', g_form.getUniqueValue());
gaSlowGlideAjaxCall.addParam('some_field_value', g_form.getValue('{field_name}'));
//Show animated form message: "Processing request..."
//This will continue to show and animate until we call stopAnimatedLoadingFieldMessage(),
// which we'll do in the callback function
//todo: Update message from "Processing request" to whatever is appropriate to your situation.
showAnimatedLoadingFieldMessage(
'{field_name}', //todo: Replace with name of field on which to show message
'Processing request', //todo: Replace with loading message text
'info' //todo: Set message type (info/warning/error)
);
//The below callback function (which clears the animated form message) will only execute
// when the slow GlideAjax call is complete. Until then, the animated message will continue.
gaSlowGlideAjaxCall.getXMLAnswer(function (answer) {
//todo: Do something with the answer here...
//Clear the animated "Processing request" field message and add a new one.
stopAnimatedLoadingFieldMessage(); //Clears the existing message after stopping the animation.
//todo: Replace the below message with something appropriate to your situation.
if (answer) { //todo: Update condition or behavior to suit your situation.
g_form.showFieldMsg(
'{field_name}', //todo: update
'Processing complete!', //todo: update
'info'
);
} else {
g_form.showFieldMsg(
'{field_name}', //todo: update
'Unable to process request!', //todo: update
'error'
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment