Tate Roth
Tera Contributor

I had a request from my users to allow delegates to approve time cards since it's not supported OOB.  The good news is I was able to accomplish this by modifying 2 business rules (I actually created copies to keep the original rules in case we ever needed them again).  The first one you need to modify is Set Approver list.  I have included the full script below.

(function executeRule(current, previous /*null when async*/) {

	current.approver_list = '';
	var timeCardApprovalService = new TimeCardApprovalService(current);
	if (timeCardApprovalService.approverOptionNotSet())
		return;
	
	if (timeCardApprovalService.shouldAutoApprove()) {
		current.state = 'Approved';
		return;
	}
	var approvers = timeCardApprovalService.approverList();
	if (approvers.length > 0)
		var text = approvers.join(',');
	
		var gr = new GlideRecord('sys_user_delegate');
		gr.addQuery('user', current.user.manager);
		gr.addEncodedQuery('ends>javascript:gs.endOfToday()');
		gr.query();
	
		while (gr.next()) {
			text += ',' + gr.getValue('delegate');
		}
	
		current.approver_list = text;

})(current, previous);

Then you need to modify the Handle Approval business rule by commenting out the line 

current.setValue('state', 'Submitted');

That appears in the multiple approvers sections at the bottom of the script.  This only works if you only need one person to approve the time sheets, if your company requires an approval by all users listed in the approval list you will need to do some additional modifications.  The other thing I need to mention is the Delegate needs to have the timecard_approver role otherwise they can't approve the time sheets in the first place.

Version history
Last update:
‎01-02-2019 06:32 AM
Updated by: