in servicenow, i create a script include var PEPcmdbclassnamepopulate = Class.create();…
- User
in servicenow, i create a script include
var PEP_cmdb_class_name_populate = Class.create(); PEP_cmdb_class_name_populate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
codegetCIClassName: function(){ var result = {}; var grciTable = new GlideRecord('cmdb_ci'); var selectedCIValue = this.getParameter('sysparm_selectedCI'); if(grciTable.get(selectedCIValue)){ result.class_name = grciTable.getDisplayValue("sys_class_name"); } return JSON.stringify(result); },and a catalog client script
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; }
code// alert("value is "+newValue); if (newValue != '') { var serverDetails = g_form.getValue('please_select_the_server_name'); alert('Server is: '+serverDetails); var ciDetails = new GlideAjax('PEP_cmdb_class_name_populate'); ciDetails.addParam('sysparm_name', 'getCIClassName'); ciDetails.addParam('sysparm_selectedCI', newValue); ciDetails.getXMLAnswer(function(result) { var response = JSON.parse(result); g_form.setValue("result", response.class_name); }); }it is working if we have only one value in the multirow variable field , but if more than one value with comma separated it shows undefined, i need if more than 1 value in the field then only takes the first value and displays the name
- Assistant
The issue you're encountering arises because your script is designed to handle a single CI at a time, but when multiple CIs are selected and they are sent as a comma-separated string, your script does not account for this format. To address this, you need to modify your script to consider only the first CI when multiple are selected. Here's how you can modify your script:
Catalog Client Script
Modify your
onChangefunction to handle the comma-separated values by splitting the string and taking only the first value: - User
result field is empty with the modified script
- Assistant
- User
working now, same i need to create one more function in the script include and a new catalog client script to achieve - If we choose a server and there is no value in the multi line varibale field then we need to glide cmdb_ci_server table and get the class name for that server which we selected in the "please_select_the_server_name" Field amd populate it in the another"server_result" field as same as the result field
- Assistant
- User
not working , please_select_the_server_name is a reference field to cmdb_ci_server table and we need the sys_class_name of that particular record.
- Assistant
- User
not working
- Assistant