Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Work notes only for ITIL users

Brian Lancaster
Kilo Patron

We have a requirement to make a certain group of ITIL users to have write access to only work notes.  I was thinking of giving them an extra role that would prevent them to write to all fields except work notes.  This seems like a lot of ACLs to write.  Is there a better way to do this?  Am I overthinking how I would write my ACLs?

1 ACCEPTED SOLUTION

I found something on the ServiceNow Guru site that let me get all fields that have change in an array.  It then allowed me to loop through them so I could determine if anything other then work notes was updated.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if (gs.hasRole('pmo_itil')){
		var gru = GlideScriptRecordUtil.get(current);
		var changedFields = gru.getChangedFieldNames().toString().split(',');
		//gs.log ("Changed Fields: " + changedFields);
		for (var i = 0; i < changedFields.length; i++){
			gs.log ("Changed Field: " + changedFields[i]);
			if (changedFields[i] != '[work_notes]'){
				gs.addErrorMessage('You do not have writes to change any fields but Work Notes');
				current.setAbortAction(true);
				return;
			}
		}
	}

})(current, previous);

 

View solution in original post

11 REPLIES 11

Brian Lancaster
Kilo Patron

Thought, Is there a way to validate every field that changed in a business rule without having to list out each filed?  Then if anything but work notes changes I can do a current.setAbortAction(true).

I found something on the ServiceNow Guru site that let me get all fields that have change in an array.  It then allowed me to loop through them so I could determine if anything other then work notes was updated.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if (gs.hasRole('pmo_itil')){
		var gru = GlideScriptRecordUtil.get(current);
		var changedFields = gru.getChangedFieldNames().toString().split(',');
		//gs.log ("Changed Fields: " + changedFields);
		for (var i = 0; i < changedFields.length; i++){
			gs.log ("Changed Field: " + changedFields[i]);
			if (changedFields[i] != '[work_notes]'){
				gs.addErrorMessage('You do not have writes to change any fields but Work Notes');
				current.setAbortAction(true);
				return;
			}
		}
	}

})(current, previous);