Set reference file to null with a business rule

Brian Lancaster
Tera Sage

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 = '';

12 REPLIES 12

Did you check the log statement, what i said?????


BALAJI40
Mega Sage

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();  
  • }

snehabinani26
Tera Guru

HI Brain,



you are running this BR in user table I assume and technical owner field is referenced to user table.


  1. var techOwner = new GlideRecord ('cmdb_ci_appl');  
  2. techOwner.addQuery('u_technical_owner', current.sys_id);  
  3. techOwner.query();  
  4. while (techOwner.next()){  
  5.   techOwner.u_technical_owner = "";  
  6.   techOwner.update();  
  7. }  



Hope this helps you