ismailsn
ServiceNow Employee

Exactly. What should be done is just get a list of records that were requested by/requested for these users that you will be deleting before you do so.



This can be done doing the following:



deleteUser();



function deleteUsers(){




  var target = new GlideRecord('sys_user');


  target.addNullQuery('user_name');


  target.addNullQuery('email');


  target.addNullQuery('ldap_server');


  target.query();


  while(target.next()){



  var taskRecords = new GlideRecord('task');


  taskRecords.addQuery('requested_for', target.sys_id );


  taskRecords.query();


  while(taskRecords.next()){




  gs.print("The record " + taskRecords.number + " is associated with sys_user record" + target.sys_id);




  }




  //Uncomment the following line when you want to commit the delete


  //target.deleteRecord();



  }




}