How to set "Assigned to" field to empty in asset table when a employee state is Terminated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 12:47 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2020 12:57 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 11:30 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:43 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2020 12:51 PM
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