Nested Queries
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2011 03:17 PM
I'm trying to create a scheduled job that will run daily to add terminated employees to inactive and remove any groups the user may have, similar to what's found here: How do I remove a user from all groups using a script
We use the LDAP code 512 for active and 514 for inactive. I made a query to find all users with a custom field valued at 514. Tested it, works great. Then I created a nested query to delete the current user's groups. This caused the script to delete every user's group, regardless of wether or not their custom field value was 514 or 512. I'm positivie the first query only returns those with a value of 514. So why would the second query in the code below work for both 512 and 514 users?
Can anyone see what i'm doing incorrectly?
cleanAD();
function cleanAD(){
var cleanRoles = new GlideRecord('sys_user_grmember');
var getInactive = new GlideRecord('sys_user');
getInactive.addQuery("u_uaccountcontrol","514");
getInactive.query();
while(getInactive.next()){
cleanRoles = new GlideRecord('sys_user_grmember');
cleanRoles.initialize();
cleanRoles.addQuery("name", getInactive.sys_id);
cleanRoles.query();
while (cleanRoles.next()){
cleanRoles.deleteRecord();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2012 06:50 AM
Be warned!
There are out-of-box queries that do not run correctly anymore when glide.invalid_query.returns_no_rows is set to true. A sample I have found (even in Berlin) was in the workflow engine, the JOIN condiction http://wiki.servicenow.com/index.php?title=Utility_Activities#Join
does not wait anymore for all tasks to be closed.