Set reference file to null with a business rule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 06:03 AM
I have a requirement that when a users account in ServiceNow is set to active = false I need to check the CMDB application table for a custom reference filed and remove their name. I setup a Business rule on the users table that fires when the active changes to false. I have the following code and with some logging I know it is finding all the records but it is just not updating them. Any thoughts on why this would be? Also any thoughts on a better way to do this as there are multiple custom reference files I need to check?
var techOwner = new GlideRecord ('cmdb_ci_appl');
techOwner.addQuery('u_technical_owner', current.sys_id.name);
techOwner.query();
while (techOwner.next()){
//gs.log('in while');
techOwner.u_technical_owner = "NULL";
techOwner.update();
}
I have also tried techOwner.u_technical_owner = '';
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 06:28 AM
Yes the BR is running on the Sys_user table and yes u_technical_owner is a reference to sys_user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 06:33 AM
HI Brain,
Then please try this code
- var techOwner = new GlideRecord ('cmdb_ci_appl');
- techOwner.addQuery('u_technical_owner', current.sys_id);
- techOwner.query();
- while(techOwner.next()){
- techOwner.u_technical_owner = "";
- techOwner.update();
- }
Please validate when to run condition of the BR

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 06:34 AM
I invite you to try your script in scripts background, using the "faux current" method listed here to debug what could be the issue. As others have pointed out (using the exact same script I wrote), the solution is there.
Faster Server Side Script Development and Test

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 07:07 AM
Thanks Chuck, ended up that this specific filed I build into the cmdb_ci table so I could use it on any of the CMDB tables.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 10:42 AM
You're welcome.
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Thank you