- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2016 02:22 PM
I am familiar with using it in reference to the current user using either g_user or gs but I am wanting to use it inside of an addQuery against my user table. Basically the goal is to walk through each user and determine if they have a role (and if they do we will execute a command). I am having issues using this against my variable I create however.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2016 02:46 PM
Hi Joe,
Using the addquery method on sys_user for roles wont fetch the roles for the given user. roles column in sys_user is not referenced. The information of the association between the roles table and user table lies in sys_user_has_role table or alternatively we can use the shortcut method of hasRole().
So we need to query against the sys_user_has_role
var role= new GlideRecord('sys_user_has_role ');
role.addQuery('user', sysid of user);
role.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2016 09:25 AM
Hi Joe,
A quick question. If it has stopped getting duplicates that means the entries are going fine on the time card check table. So when you say still showing empty are these the old records that got inserted? If not, then are you not getting duplicates any more because there is a empty user value record in u time card check.
If no more values are getting inserted. Can you log after the while loop starts for user sys id to see what is happening here
gs.log(grUserRole.user.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2016 09:27 AM
Also do check for the column name defined hope it is user in your u_time_card_check table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2016 09:30 AM
I misspoke in my last reply so I deleted (but unfortunately you read and responded), I apologize for that. I am now getting the user field populated perfectly but I DO have duplicates.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2016 08:17 PM
Avoid duplicates
var grUserRole = new GlideAggregate('sys_user_has_role');
grUserRole.addQuery('role','ef0c18e2372231000ddf26877e41f1d0');
grUserRole.groupBy('user');
grUserRole.query();
while (grUserRole.next()) {
var tcp = new GlideRecord('u_time_card_check');
tcp.initialize();
tcp.user = grUserRole.user.sys_id;
tcp.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2016 09:46 AM
that is great. So are you still getting duplicates. If yes, then write a business rule on time card to check on user. For sample you can look for business rules have name prevent duplicates. Also you need to remove the existing duplicates by going to that table and seeing for duplicates. If you have a lot of records then we may need to write a fix script and run it once.