Apply Minimum 40 hours to time sheet portal

maneesh3
Tera Contributor

Hi Team,

 

How to apply minimum hours to be filled by user to 40 in time sheet portal. I have verified time sheet properties but I saw only Maximum hours property. Help me here how to achieve minimum hours rule to be applied while clicking on Submit button validation has to happen.

 

Thanks for support

6 REPLIES 6

SumanthDosapati
Mega Sage
Mega Sage

Hi @maneesh3 

OOB, there is no such option. You have to write a business rule to restrict it.

 

Regards,
Sumanth

Hi Sumanth,

 

Thanks for the response, Could you provide me BR script to implement this. 

 

 

Hi Sumath,

 

Can you please help with BR Script for this , thanks for your help!

 

 

Hi Sumanth,

 

Can you please help me with BR script for above requirement . Tried below but not working:

 

(function executeRule(current, previous /*null when creating*/ ) {
    var totalHours = 0;
var weekStartDate = current.week_starts_on; // Assuming this is the field for the week start date

    // Query all time entries for the current week
    var timeCardGR = new GlideRecord('time_sheet');
   timeCardGR.addQuery('week_starts_on', weekStartDate);
//  timeCardGR.addQuery('time_sheet', current.sys_id);
    timeCardGR.query();

    while (timeCardGR.next()) {
        totalHours += timeCardGR.total_hours;
    }

    // If the total hours for the week are less than 40, prevent the save
    if (totalHours < 40) {
        gs.addErrorMessage('You must submit at least 40 hours for the current week.');
        current.setAbortAction(true);
    }
})(current, previous);