Script Required - User user record with name of Catalog Item user has requested

steveturley
Tera Guru

Hi. I'm looking to build an inventory on the user record of the catalog items a user has requested and thus, been supplied.

e.g. If a RITM has been processed to grant catalog item 'Software A', then 'Software A' shows against that user record. I thought a list collector on the user record of sc_cat_items would be best to do this.

Therefore, I need a script to run in the workflow to add the name if the catalog item to the user record.

 

Hope this makes sense! Thanks!

4 REPLIES 4

Amit Verma
Kilo Patron
Kilo Patron

Hi @steveturley 

 

Do you want a list of the requestor vs the catalog item being requested by them ? I am not able to understand this statement "I need a script to run in the workflow to add the name if the catalog item to the user record.". If you could please elaborate on your requirement.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Apologies, there's a typo in my text.

 

Yes, the requirement is to be able to see from the user record the catalog items requested by them. However, some of the items can be requested by one person for another, so I realise it would need to use the 'Requested For'

I've created a list collector of the catalog items on the user record and would like the script to add the catalog item to the user record. (Please see screenshot below)

 

Screenshot 2024-03-11 102447.png

Anirudh Pathak
Mega Sage

Hi @steveturley ,

Create an "after insert" business rule on "sc_req_item" table.

Please use the below code - 

var user = current.requested_for;
var catItem = current.cat_item;

	var userGr = new GlideRecord('sys_user');
	if(userGr.get(user)) {
		var arr = [];
		arr.push(userGr.u_test_catalog_item); // replace your list collector field name
		arr.push(catItem);
		userGr.u_test_catalog_item = arr.toString(); // replace your list collector field name
		userGr.update();
	}

 

Hi @Anirudh Pathak 

I've just two tests, one requesting the item for myself and one when I requested the item for another user. It didn't work for myself, but did for the other user - any idea why that would be? (I do know ServiceNow is sometimes funny if the same user processes a ticket for that user)

It does seems to work though - thanks! The reason I was looking to place it in the workflow was so that if the Request was to 'add' the software, the item would be added. However, if the request was to 'remove' the software, I could have another script to do that - do you have any ideas?

 

I'm very grateful for your script above though - thank you!