To fulfill your requirement, you would generally implement a change in the client script section of your ServiceNow form for the catalog item. The script will trigger upon selection of a server (assumed to be the ‘onChange’ event for the ‘select_server’ reference field). It needs to execute a server-side script using GlideAjax to check for operational virtual servers related to the selected physical server.
Here’s a rough breakdown of the steps required:
-
Client Script: This script runs on the client side when the 'select_server' field value changes. It sends the selected server's sys_id to a Script Include, which handles server-side logic.
-
Script Include: This server-side script uses the received sys_id to search the cmdb_rel_ci table for any operational virtual servers related to the selected physical server in cmdb_ci_server. The operational status is assumed to be flagged in some way on these records.
-
Ajax Response: Depending on the result from the Script Include, you send back a response to the client script.
-
Client Script Notification: If operational virtual servers are found, the client script then triggers a pop-up message to inform the user.
Example Implementation
Client Script (Type: onChange)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Creating a new GlideAjax object, pointing to our Script Include - 'CheckOperationalServers'
var ga = new GlideAjax('CheckOperationalServers');
ga.addParam('sysparm_name', 'getOperationalStatus');
ga.addParam('sysparm_server_sys_id', newValue);
// Getting the response and acting based on it
ga.getXMLAnswer(function(answer) {
if (answer == 'true') {
// Virtual operational servers found, show popup
alert('Operational virtual servers are tagged with this physical server.');
}
});
}
Script Include (Global, Client Callable)
var CheckOperationalServers = Class.create();
CheckOperationalServers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOperationalStatus: function() {
var serverSysId = this.getParameter('sysparm_server_sys_id');
var relRecord = new GlideRecord('cmdb_rel_ci');
relRecord.addQuery('parent', serverSysId);
relRecord.addQuery('child.operational_status', 'operational'); // Assuming 'operational' status is identified this way
relRecord.query();
if (relRecord.next()) {
return 'true'; // Found at least one operational virtual server
}
return 'false';
}
});
Note that this code makes some assumptions about your data model and operational status. You would need to adjust the logic to fit your exact schema and requirements, especially the logic identifying operational virtual servers within the getOperationalStatus method in the Script Include.
Lastly, ensure to test any script in a non-production environment first to avoid unexpected outcomes.