How to set "Assigned to" field to empty in asset table when a employee state is Terminated

nishtha6
Tera Contributor

Hi,

Can someone tell be how to set Assigned to field to Empty if a user is terminated.

This i am asking to do in Asset table.

Basically, User left the company and he has so many assets assigned. The client need that we need to remove all the Assets from the user in servicenow Asset table when user record is terminated.

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

You could set up a Business Rule, after or async, on update on the User table [sys_user]. Just select the conditions you are after, for example active changes to false.

As script you could use something like:

var grCI = new GlideRecord('cmdb_ci');
grCI.addQuery('assigned_to', current.getUniqueValue());
grCI.setLimit(10);

grCI.clearValue('assigned_to');
grCI.setWorkflow(false);
grCI.updateMultiple();

For testing purposes added grCI.setLimit(10);

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

i am not getting the desired value after doing it. attachingfind_real_file.pngfind_real_file.png screenshots

I would expect a different condition. Update, and for example Employee Status changes to Terminated.

So what is not working about the script? Did you debug it? Is the script executed at all? Etc..

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I would expect a different condition. Update, and for example Employee Status changes to Terminated.

Can you try below script?

var grCI = new GlideRecord('cmdb_ci');
grCI.addQuery('assigned_to', current.getUniqueValue());
grCI.setLimit(10);
grCI.query();

while(grCI._next()) {
	grCI.setValue('assigned_to', '');
	grCI.setWorkflow(false);
	grCI.update();
}

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn