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.

Script Help

DEEPAK KUMAR SI
Tera Contributor

Hi All,

I am not a PRO in scripting hence need a bit guidance. I have a UI action which should be visible on some conditions and that condition is too long

----------------------------------------

Visibility Conditions

------------------------

Field Values: Display the button when the value of the “u_cmdbci_review_cycle” field is either “Review Started” or “Review Overdue”.
Support Group Membership: If the user is a member of the support group specified in the “support_group” field, show the button.
Owned By or Managed By: If the user’s name appears in the “owned_by” or “managed_by” or "alternate contacts (it can contains multiple users)" fields, display the button.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

When you've reached the character limit on the Condition field, it's time to call a Script Include.  You can have the SI handle everything, or do what you were doing for Field Values, and Support Group.  Your new condition would look something like this:

(current.u_cmdbci_review_cycle=='Review Started'||current.u_cmdbci_review_cycle=='Review Overdue')&&gs.getUser().isMemberOf(current.support_group)&&new CMDBUtils().showButton(current);

or just 

new CMDBUtils().showButton(current);

The Script Include to handle only the last criteria would look like this:

var CMDBUtils = Class.create();
CMDBUtils.prototype = {
	initialize: function() {},
	
	showButton: function(ci) {
		var usr = gs.getUser();
		if (usr == ci.owned_by || usr == ci.managed_by || ci.alternate_contacts.toString().indexOf(usr) > -1) {
			return true;
		} else {
			return false;
		}
	},

	type: 'CMDBUtils'
};

 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

When you've reached the character limit on the Condition field, it's time to call a Script Include.  You can have the SI handle everything, or do what you were doing for Field Values, and Support Group.  Your new condition would look something like this:

(current.u_cmdbci_review_cycle=='Review Started'||current.u_cmdbci_review_cycle=='Review Overdue')&&gs.getUser().isMemberOf(current.support_group)&&new CMDBUtils().showButton(current);

or just 

new CMDBUtils().showButton(current);

The Script Include to handle only the last criteria would look like this:

var CMDBUtils = Class.create();
CMDBUtils.prototype = {
	initialize: function() {},
	
	showButton: function(ci) {
		var usr = gs.getUser();
		if (usr == ci.owned_by || usr == ci.managed_by || ci.alternate_contacts.toString().indexOf(usr) > -1) {
			return true;
		} else {
			return false;
		}
	},

	type: 'CMDBUtils'
};