Catalog Item and its Workflow modification

abhi_b
Tera Contributor

I have a query in Service Now:
I have a catalog item "Management of Distribution List/Security Group" in which we have many variables but taking only some variable for now which related to my query :
1. Request type (which is a Select Box having three categories "Create", "Delete", "Modify")
2. Type of Item (which is also a Select Box having three categories "Distribution List", "Security Group", "Mail Enabled Security Group")
3. Name of the group (which is also a Single Line Text)
4. List of user(s) to be added to the group (which is a List Collector has values referenced from sys_user table)
5. List of user(s) to be removed from group (which is a List Collector has values referenced from sys_user table)

 


When we select request type as Modify so two more variables comes 1. Add user(s) to the group and 2.Remove user(s) from the group,  which are Checkbox type

Screenshot 2024-03-13 at 2.10.22 PM.png

 

 

So I want to make some edits to its workflow. So when we select Add user, I want to change the Short Description of the RITM and SCTASK (that is generated after submitting the request from that catalog item) to be the values entered in variables  Request Type, Type of Item, Name of the group

 

At present Short Description for the RITM and SCTASK is combination of 3 [Request type - Type of item - Name of the Group] for every Request type category "Create", "Delete", and "Modify".

 

If Request type = Create/delete

Short Description = Request type + Type of item + Name of the Group

 

But I need changes are as follows :
1.    if Request Type = Modify
and  we have to "Add user(s) to the group"
Then Short Description of the RITM and SCTASK to be Request Type + Type of Item + Name of the group + 
List of user(s) to be added to the group

2.   if Request Type = Modify
and we have to "Remove user(s) to the group"
Then Short Description of the RITM and SCTASK to be Request Type + Type of Item + Name of the group + Remove User [User's Name]

 

This is the screenshot of the workflow that is attached to the catalog item:

Screenshot 2024-03-13 at 2.14.33 PM.png

 

For the Run Script with Name "Set RITM Short Description and Description"

It has code :

 Screenshot 2024-03-13 at 2.20.07 PM.png

 

 

Any help will be appreciated. Thanks in Advance

 

Regards,

Abhishek

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

I always forget if getDisplayValue() can be used on a server script for list / list collectors, so the first two if block contents may be able to be replaced with that instead of the GlideRecords, but this will get you there too:

if (current.variables.users_add) { //name of your add users list variable
	var userAddArr = [];
	var userAdd = new GlideRecord('sys_user');
	userAdd.addQuery('sys_id', 'IN', current.variables.users_add);
	userAdd.query();
	while (userAdd.next()) {
		userAddArr.push(userAdd.name); //or whatever field on the user table you want to show in the description
	}
	
	current.short_description = current.variables.request_type + ' ' + current.variables.type_of_item + ' - ' + current.variables.name_of_the_group + ': ' + userAddArr.join(',');

} else if (current.variables.users_del) { //name of your remove users list variable
	var userDelArr = [];
	var userDel = new GlideRecord('sys_user');
	userDel.addQuery('sys_id', 'IN', current.variables.users_del);
	userDel.query();
	while (userDel.next()) {
		userDelArr.push(userDel.name); //or whatever field on the user table you want to show in the description
	}

	
	current.short_description = current.variables.request_type + ' ' + current.variables.type_of_item + ' - ' + current.variables.name_of_the_group + ': ' + userDelArr.join(',');

} else {
	current.short_description = current.variables.request_type + ' ' + current.variables.type_of_item + ' - ' + current.variables.name_of_the_group;
}

current.description = current.variables.business_justification;