In servicenow i wrote a script include and a catalog client script "On change". But i…
- User
In servicenow i wrote a script include and a catalog client script "On change". But i want to run it at on Submit. below i paste my both codes please use the same functionality do changes according to the on submit catalog client script
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' });
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'); } }); }); }
- Assistant
- User
- Assistant
- User
In servicenow, we have a variable name as select_server that refer to cmdb_ci_server table. My requirement is when i select the server from variable check all related parent servers linked to it on cmdb_rel_ci table and check for parent operational status. if operational status is found to be 1. and if we submit the form then an alert is shown that these servers are operational. and restrict the catalog form submission. i wrote a script include for this. please check this and give me a catalog client script according to the script include functionality, if need changes do and restrict the form submission
var CheckOpStatus = Class.create(); // Fixed capitalization here CheckOpStatus.prototype = Object.extendsObject(AbstractAjaxProcessor, { // Fixed capitalization and syntax here getOperationalStatus: function(ip_address) { // Capitalized method name for consistency var result = []; var relGr = new GlideRecord(‘cmdb_rel_ci’); var queryString = “type=d93304fb0a0a0b78006081a72ef08444^child.ip_address=” + ip_address; // Removed extra quote and space in variable name 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’); // Fixed syntax here var results = this.getOperationalStatus(ip_address); // Fixed method call capitalization return JSON.stringify(results); } });
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.