Auto create Timesheet for timecard_users

Community Alums
Not applicable

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!!

 

SubhikshaNaray_0-1714923261038.png

 

3 REPLIES 3

Kieran Anson
Kilo Patron

Hey,

The OOB script will only create timecards on the following basis

  1. The user has the timecard_user role
  2. They're active
  3. They're a member of the group you provided
  4. They're not a member of the exclusion group
  5. If the sys_user record has a time sheet policy, the policy needs to have "Auto create time cards every week" set to true
    1. Otherwise it fallsback to the OOB default policy which has "Auto create time cards every week" set to true

Community Alums
Not applicable

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

 

SubhikshaNaray_0-1714933129437.png

SubhikshaNaray_3-1714933174813.png

 

 

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"]))
			}

}