In servicenow, In a catalog item,i have a reference variable named as selectserver and…
- User
In servicenow, In a catalog item,i have a reference variable named as select_server and referring to cmdb_ci_server table. my requirement is that if i select any server from select_server variable then it will take the ip_address from the selected record and check for all the parent virtual server on cmdb_rel_ci table through the ip_address with a encoded query child.ip_address = ip_address of the selected server and then checks for the operational status of all parent records in cmdb_rel_ci table come after encoded query and note the names of all servers whose operational status is 1 and show the names of all operational server in a popup or alert box before submitting the form. i want this requirement to be check before submmiting the catalog request and prevent the user to submit the request until the alert box and all servers was not shoing in the alert. i want to restrict the user to submit the request
- Assistant
- User
give both script with this requirement For the part where you want to prevent form submission until all operational servers are shown in an alert, you could modify the Client Script to set a flag on the form that indicates whether the check has passed or not, and use an onSubmit client script to prevent form submission based on that flag.
- Assistant
- User
Script include
var Checkopstatus = Class.create(); CheckOpStatus.prototype= Object.extendsobject(AbstractAjaxProcessor, { getoperationalstatus: function(ip_address) { var result =[]; var relGr = new GlideRecord('cmdb_rel_ci'); var queryString = "'type=d93304fb0a0a0b78006081a72ef08444^child.ip_address=" + ip_ address; relGr.addEncodedQuery(queryString); relGr.query(); while (relGr.next()) { var parent = relGr.parent.getRefRecord(); if (parent && parent.operational_status == '1' ) { result.push(parent.name.toString()); } } return result; }, ajaxFunction_getParentNames: function() { var ip_address = this.getParameter('sysparm_ip_address'): var result2 = this.getOperationalStatus(ip_address); return JSON.stringify(result2); }, type: 'CheckOpStatus' });
Client script
[10:54] Deepak Sharma function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } g_form.getReference('select_server', function(ref) { var ip_address = ref.ip_address; var ga = new GlideAjax('CheckOpStatus'); ga.addParam('sysparm _name', 'getParentNames' ); ga.addParam('sysparm_ip_address', ip_address); ga.getXMLAnswer (function(answer) { var result = JSON. parse(answer); if (result.length > 0 ) { var names = result.join(', '); alert("servers tagged to the Physical server " + result.join(', ')); g_form.clearvalue('select_server'); g_form.setValue('validation_passed', 'false'); } }); }); }
- Assistant
- User
not working.. form still submit while loading the servers
- Assistant