how to restrict the operation statues in list view

SaitejaN
Tera Contributor

when some one changes the operational status when install status is installed it has to restrict operational status. And   pop up the alert message. It has to work only when we try to change operational to other state. Can anyone help on this?

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hello @SaitejaN ,

 

I tried and got a Client Script and Script include to work. I am using records in the 'cmdb_ci' table to test.

 

Client script:

Screenshot 2025-06-19 183101.png

Script:

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {

    //Type appropriate comment here, and begin script below
	var saveAndClose = true;
	var validateData = new GlideAjax('MyCMDBUtils');
	validateData.addParam('sysparm_name', 'checkInstallStatus');
	validateData.addParam('sysparm_ids', sysIDs);
	validateData.addParam('sysparm_opstat', newValue);
	validateData.getXMLWait();
	if (validateData.getAnswer() === 'false') {
		alert("Operational Status may not be changed for Installed configuration item");
		saveAndClose = false;
	}
	callback(saveAndClose);
}

The script include is needed to access the record:

Screenshot 2025-06-19 183123.png

Script:

var MyCMDBUtils = Class.create();
MyCMDBUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	checkInstallStatus: function() {
		var recID = this.getParameter("sysparm_ids");
		var opStatus = this.getParameter("sysparm_opstat");
//		gs.info('checkInstallStatus: sys_id = ' + recID + ', os = ' + opStatus);
		var retValue = true;
		var item = new GlideRecord('cmdb_ci');
		var rec = item.get(recID);
		if ((rec)  && (item.install_status == 1)) {
			// prevent editing for Installed
			retValue = false;
		}
//		gs.info('checkinstallStatus: returning ' + retValue);
		return retValue;
	},

    type: 'MyCMDBUtils'
});

Change names as desired.

View solution in original post

12 REPLIES 12

SaitejaN
Tera Contributor

Here is the Detailed Explanation so in my list view I do have the both install and operational status. Here when someone changes the operational field manually the system has to throw the error message like "You cannot change operational status manually when installed status is installed". And if the operational status is any state other than operational  restriction should not be occurred.

Bert_c1
Kilo Patron

See:

 

https://www.servicenow.com/community/itsm-forum/how-to-restricting-fields-in-list-view/td-p/721907

 

however, a specific solution was not provided, but helped the member who posted the same request.

SaitejaN
Tera Contributor

Thanks @Bert_c1 but I am looking for exact solution, I have  been using all scripts noting is successful.

Bert_c1
Kilo Patron

Hello @SaitejaN ,

 

I tried and got a Client Script and Script include to work. I am using records in the 'cmdb_ci' table to test.

 

Client script:

Screenshot 2025-06-19 183101.png

Script:

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {

    //Type appropriate comment here, and begin script below
	var saveAndClose = true;
	var validateData = new GlideAjax('MyCMDBUtils');
	validateData.addParam('sysparm_name', 'checkInstallStatus');
	validateData.addParam('sysparm_ids', sysIDs);
	validateData.addParam('sysparm_opstat', newValue);
	validateData.getXMLWait();
	if (validateData.getAnswer() === 'false') {
		alert("Operational Status may not be changed for Installed configuration item");
		saveAndClose = false;
	}
	callback(saveAndClose);
}

The script include is needed to access the record:

Screenshot 2025-06-19 183123.png

Script:

var MyCMDBUtils = Class.create();
MyCMDBUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	checkInstallStatus: function() {
		var recID = this.getParameter("sysparm_ids");
		var opStatus = this.getParameter("sysparm_opstat");
//		gs.info('checkInstallStatus: sys_id = ' + recID + ', os = ' + opStatus);
		var retValue = true;
		var item = new GlideRecord('cmdb_ci');
		var rec = item.get(recID);
		if ((rec)  && (item.install_status == 1)) {
			// prevent editing for Installed
			retValue = false;
		}
//		gs.info('checkinstallStatus: returning ' + retValue);
		return retValue;
	},

    type: 'MyCMDBUtils'
});

Change names as desired.