Created
May 5, 2022 20:56
-
-
Save cmcdevitt/769f31d5804da7eb2c99403b2e840a5d to your computer and use it in GitHub Desktop.
ServiceNow AJAX Client and Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Client Side | |
| UI Action | |
| Client = checked | |
| Action name = your_choice | |
| OnClick = onClickFormButton() | |
| */ | |
| function onClickFormButton() { | |
| g_form.clearMessages(); | |
| if (g_form.modified) {//Test for a dirty cache | |
| g_form.addErrorMessage(getMessage("You must save before proceeding.")); | |
| return false; | |
| } | |
| processExtras(); | |
| } | |
| function processExtras() { | |
| var extra_process = g_form.getValue('u_post_processing_script'); | |
| var ajax = new GlideAjax("CmVRAJAX"); //Script Include | |
| ajax.addParam("sysparm_name", "processExtras"); //Method | |
| ajax.addParam("sysparm_assignment_rule_sys_id", g_form.getUniqueValue().toString()); //pass to script | |
| ajax.addParam("sysparm_extra_process", extra_process); | |
| ajax.getXML(parseResponse); //function in calling script | |
| } | |
| function parseResponse(response) { | |
| var answer = response.responseXML.documentElement.getAttribute("answer"); | |
| if (answer) { | |
| g_form.addInfoMessage(answer); | |
| } | |
| } | |
| /* | |
| Server Side | |
| Script Include | |
| Client callable = checked | |
| Accessible from = All application scopes | |
| */ | |
| var CmVRAJAX = Class.create(); | |
| CmVRAJAX.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { | |
| processExtras: function() { | |
| var extras = this.getParameter("sysparm_extra_process"); //FROM CLIENT | |
| var ar_sys = this.getParameter("sysparm_assignment_rule_sys_id"); | |
| if(extras == 'add ports'){ | |
| //gs.addInfoMessage("adding Ports!"); | |
| this._addPortsToCondition(); | |
| return "Adding Ports"; //TO CLIENT | |
| }else{ | |
| //gs.addInfoMessage("No Extras to process..."); | |
| return "Nothing to process";//TO CLIENT | |
| } | |
| }, | |
| _addPortsToCondition: function() {//Private Function | |
| var util = new sn_vul.VrArUtils(); | |
| var ar_sys = this.getParameter("sysparm_assignment_rule_sys_id"); | |
| util.addPortsToCondition(ar_sys); | |
| }, | |
| type: 'CmVRAJAX' | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment