Auto create Timesheet for timecard_users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 08:44 AM
Hii Everyone,
I'm not sure what should be the actual behavior for the OOB scheduled job "Auto Generate Time Cards" but I'm actually on a quest to auto create new timesheets for the users at the start of each week (sunday), for those with the timecard role, found the below script but however when executes it create timesheet only for a single user
Added include and exclude groups to the OOB script
hoping for a helping hand please!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 09:42 AM
Hey,
The OOB script will only create timecards on the following basis
- The user has the timecard_user role
- They're active
- They're a member of the group you provided
- They're not a member of the exclusion group
- If the sys_user record has a time sheet policy, the policy needs to have "Auto create time cards every week" set to true
- Otherwise it fallsback to the OOB default policy which has "Auto create time cards every week" set to true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 11:20 AM
Heyy Hi Kieran,
Thanks you so much for the explanation ,but I've double-checked all the stuff you mentioned, but it's still not kicking in

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2024 06:15 AM
You can run parts of the TimeCardGenerator script include to work out where it could be failing for you,
For example, the below will print out Yes or No on whether the users should have an auto-generated time card
var includeGroups = [];
var excludeGroups = [];
var timeCardUserRoleId = TimeCardUtil.getTimeCardUserRoleId();
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('role', timeCardUserRoleId);
gr.addQuery('state', 'active');
gr.addQuery('user.active', true);
var sq = gr.addJoinQuery('sys_user_grmember', 'user', 'user');
if (JSUtil.notNil(includeGroups) && includeGroups.length > 0)
sq.addCondition('group', 'IN', includeGroups.join(',')).addOrCondition('group.name', 'IN', includeGroups.join(','));
if (JSUtil.notNil(excludeGroups) && excludeGroups.length > 0)
sq.addCondition('group', 'NOT IN', excludeGroups.join(',')).addCondition('group.name', 'NOT IN', excludeGroups.join(','));
gr.query();
var users = [];
var arrayUtil = new ArrayUtil();
while (gr.next()) {
var userId = gr.getValue('user');
if (arrayUtil.contains(users, userId))
continue;
users.push(userId);
if(this.shouldGenerateTimeCardsForUser(userId)){
gs.info(gs.getMessage("{0} - TimeCard Setting - {1}", [gr.getDisplayValue('user') , "Yes"]))
} else {
gs.info(gs.getMessage("{0} - TimeCard Setting - {1}", [gr.getDisplayValue('user') , "No"]))
}
}