In this blog post, I will try to cover how to handle the time entry input in NetSuite pages and if there is a need to automatically increment the time entered to the next time value.

The time entry is used in various pages in NetSuite such as daily timesheet entry, weekly timesheet entry, task-based time entry etc. 

Before we begin, we must first decide what should be the criteria for time increment.

For example, if it is within task-based time entry, it could be based on the task type or project type or the customer. The same also applies to daily timesheet entry as well as weekly timesheet.

This increment deciding factor is referenced in the script example below as “increment factor” and also as “billable Measure”.

For the purpose of this example, we will assume time increment examples of 10th min and 25th min. When user inputs time entry, we will write client-side validation to increment the time. For example, if user input 6 mins, this script will automatically change to 10 min if the increment Factor is 10.

So, let us begin first by creating a client-side script

Within daily timesheet entry, the field that captures the time entry by user is “hours”.

We need to handle the “fieldChanged” event.

function fieldChanged(scriptContext)

{

               try {

               var fieldChanged = scriptContext.fieldId;

               var currentRecord = scriptContext.currentRecord;

               if (fieldChanged== ‘hours’)     

               {

                               var timeEntry_hours = currentRecord.getValue({fieldId : “hours”});

                               //currentRecord that User is editing.

                    //increment_factor is the 10th min and 25th min rounding that we show in below example.

                   //reCalcHours is the function that handles the “hours”.

                               var newHours = reCalcHours(timeEntry_hours,increment_factor); //function

                               currentRecord.setValue({

                                              fieldId: ‘hours’,

                                              value: newHours,

                                              ignoreFieldChange : true

                               })

               }

               }

}

function reCalcHours(hoursToCheck,billableMeasure)

{

               var decimalPart = getFraction(hoursToCheck); //getFraction is a function to get decimal part of the number.

               var integerPart = Math.trunc(hoursToCheck);

               var billableIncrement = parseFloat(billableMeasure);

               // In the below example, we have shown 10th and 25th increment. However this can be customized with a for loop.

               if (billableIncrement ==25) //25th Min

               { // SWITCH statement can be used here, but for easy understanding IF is shown

                               if (decimalPart >= 0 && decimalPart <= 0.25)

                                              return integerPart +  0.25;

                               if (decimalPart > 0.25 && decimalPart <= 0.50)

                                              return integerPart +  0.50;

                               if (decimalPart > 0.50 && decimalPart <= 0.75)

                                              return integerPart +  0.75;

                               if (decimalPart > 0.75)

                                              return integerPart +  1;

               }

               if (billableIncrement == 10) //10th Min

               { // SWITCH statement can be used here, but for easy understanding IF is shown

                               if (decimalPart >= 0 && decimalPart <= 0.1)

                                              return integerPart +  0.1;

                               if (decimalPart > 0.1 && decimalPart <= 0.2)

                                              return integerPart +  0.2;

                               if (decimalPart > 0.2 && decimalPart <= 0.3)

                                              return integerPart +  0.3;

                               if (decimalPart > 0.3 && decimalPart <= 0.4)

                                              return integerPart +  0.4;

                               if (decimalPart > 0.4 && decimalPart <= 0.5)

                                              return integerPart +  0.5;                      

                               if (decimalPart > 0.5 && decimalPart <= 0.6)

                                              return integerPart +  0.6;

                               if (decimalPart > 0.6 && decimalPart <= 0.7)                         {

                                              return integerPart +  0.7;

                               if (decimalPart > 0.7 && decimalPart <= 0.8)

                                              return integerPart +  0.8;

                               if (decimalPart > 0.8 && decimalPart <= 0.9)

                                              return integerPart +  0.9;

                               if (decimalPart > 0.9)

                                              return integerPart +  1;

               }

    return hoursToCheck;

}

As you can see, the user input will be automatically changed within the page. This helps the approvers of the time entries to have the automatic increment taken care without having to manually check the entries.

Feel free to contact us for any questions.

Wait! Before You GoWould you like to talk to a business software expert to answer your questions?

When you schedule a free consultation with MIBAR, you will experience a one-on-one conversation with a business technology expert who is passionate about understanding your unique needs or issues. Schedule a free consultation today at the link below or give us a call at (212) 869-9300.

Learn More
NetSuite Offer: Save $15,000 With Our Limited-Time Discount

If you’ve been evaluating NetSuite, there is no better time to make the switch. With a NetSuite subscription through MIBAR by December 31, 2020, we will offer you 75 hours of professional consulting services for FREE.

Not only can a new ERP system like NetSuite help you reduce operating costs by automating manual processes, but this limited time offer can also help save you a substantial amount of money upfront.