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:35 AM
Did you check the log statement, what i said?????
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 06:09 AM
Please change the second line,
- var techOwner = new GlideRecord ('cmdb_ci_appl');
- techOwner.addQuery('u_technical_owner', current.user_name); // give the user name of back end name and check
- techOwner.query();
- while (techOwner.next()){
- //gs.log('in while');
- techOwner.u_technical_owner = "NULL";
- techOwner.update();
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 06:11 AM
HI Brain,
you are running this BR in user table I assume and technical owner field is referenced to user table.
- 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();
- }
Hope this helps you