Weekly Timesheet

The Weekly Timesheets feature works in conjunction with the existing Time Tracking feature to offer a customizable method of capturing time entries in a weekly format. Each timesheet represents a single week, and includes a sublist where each line represents a day of the week.

For help working with this record in the UI, see Weekly Timesheets.

The internal ID for this record is timesheet. In this newest version of the timesheet record, each sublist line representing a day of the week is a time record. The time record has an internal ID of timebill. In the deprecated version of the timesheet record, the values in the sublist are from a timeentry subrecord. The timeentry subrecord is not used by the newest version of the timesheet record.

See the SuiteScript Records Browser for all internal IDs associated with the timesheet record, and internal IDs associated with the Time record. The records browser entry for the timesheet record may include field IDs for the deprecated version of the record.

Note:

For information about using the SuiteScript Records Browser, see Working with the SuiteScript Records Browser in the NetSuite Help Center.

To track time with weekly timesheets, an administrator should go to Setup > Company > Setup Tasks > Enable Features > Employees, check the Time Tracking and Weekly Timesheets boxes, and click Save. To enable the optional new interface for Weekly Timesheets, go to Setup > Company > Setup Tasks > Enable Features > Employees. Check the New Weekly Timesheets Interface box, and click Save. After this feature is enabled, all users with timesheet permissions use the new UI. For more information, see Scripting Impact of New Weekly Timesheets Interface.

See Weekly Timesheet Record Actions and Weekly Timesheet Record Macros for the actions and macros associated with this record. For more information about actions and macros, see Overview of Record Action and Macro APIs.

For information about scripting with this record in SuiteScript, see the following help topics:

Supported Script Types

Both client and server scripts are supported for the weekly timesheet record.

Supported Functions

The weekly timesheet record is fully scriptable, which means that the record can be created, updated, copied, deleted, and searched using SuiteScript.

Scripting Impact of New Weekly Timesheets Interface

NetSuite 2018.1 supports an optional new UI for weekly timesheets.

If this new UI is enabled in your account, you may need to update your scripts on timesheets and time records, to ensure that they continue to work properly. The following changes in the new UI impact scripts on timesheet or time records:

IDs for Popup Window Fields

The new UI allows some fields to be moved to a popup window for each day. Fields that are moved to the popup window have new field IDs for each day. By default, setting the value of a popup window field updates the field's values for all days of the week, in other words, all timebills in a weekly timesheet. You can make it possible to update a field's value for a single day by appending a number 0-6 to the end of the existing field ID. For example, memo0 represents the memo field for the first day of the week.

Client scripts on fields may need to be adjusted. Any scripts intended to change a field located in a popup window should be adjusted to accommodate new field IDs for single days of the week.

In addition, any scripts that are set to run on multiple forms that may or may not have the required fields in the expected locations are likely to fail. If you have client scripts that are set to run on multiple custom forms, you must ensure that the fields are located in the expected place on all forms. The preferred method is to use user event scripts instead of client scripts to update single timebills on a weekly timesheet.

Changes to User Event Context Types

When the new UI is not enabled, there are 3 separate user event execution contexts (context.UserEventType) for approving, rejecting, or submitting a timesheet. With the new UI enabled, all of these actions use the EDIT user event type, so you must update your user event scripts for timesheets and time records. Instead of checking for a specific execution context type, these scripts should check the Approval Status field to determine whether it has been changed.

Enforcement of Defined Time Limits

When the new UI is not enabled, time limits are only validated when time transactions are submitted through the UI. With the new UI enabled, time limits are validated when an individual time transaction is added using SuiteScript. You must ensure that time transactions submitted using SuiteScript meet defined time limits.

Code Samples

The following samples are for SuiteScript 2.0:

Creating a New Weekly Timesheet

          /**
*@NapiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/record'], function(record) {
    var weeklyTimesheet = record.create({
        type: record.Type.TIME_SHEET,
        isDynamic: true
    });
    weeklyTimesheet.selectNewLine({
        sublistId: 'timeitem'
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'customer',
        value: '48'});
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'item',
        value: '117'});
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'location',
        value: '1'
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'hours0',
        value: '8'
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'memo',
        value: 'timeentry created'
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'isbillable',
        value: true
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'payrollitem',
        value: '2'
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'paidexternally',
        value: true
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'price',
        value: '1'
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'overriderate',
        value: true
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'department',
        value: '1'
    });
    weeklyTimesheet.setCurrentSublistValue({
        sublistId: 'timeitem',
        fieldId: 'class',
        value: '1'
    });
    weeklyTimesheet.commitLine({
        sublistId: 'timeitem'
    });

    var weeklyTimesheetId = weeklyTimesheet.save();
}); 

        

Verifying Total Hours Upon Submit

          /**
*@NapiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/ui/dialog', 'N/error'], function(dialog, error) {
    function saveRecord(context) {
        var timesheetRecord = context.currentRecord;

        if (timesheetRecord.getValue('totalhours') !='40') {
            dialog.alert({
                title: 'Alert',
                message: 'Total time is not equal to 40'
            });

            throw error.create({
                name: 'MISSING_REQ_ARG',
                message: 'Total time is not equal to 40'
            });
        }
        return true;
    }
    return {
        saveRecord: saveRecord
    };
}); 

        

Updating a Custom Field on a Weekly Timesheet Based on Time Entry Field Values

          /**
*@NapiVersion 2.x
*@NScriptType ClientScript
*/
define(['N/record'], function(record) {
    /*
    * Populates custom field 'custrecord_am_timesheet_billable_hours' with sum of time entry 'hours'
    * values for time entries that are billable. Returns true to continue with record submit;
    */  
    function timesheet_clientSaveRecord(context) {
        var timesheetRecord = context.currentRecord;

        var intSum = 0;
        var intNumberLines = timesheetRecord.getLineCount({
             sublistId: 'timeitem'
        });
        var arTimeGridColumns = ['hours0','hours1','hours2','hours3','hours4','hours5','hours6'];

        for (var intLineCounter = 0; intLineCounter < intNumberLines; intLineCounter++){
            for (var intDayCounter = 0; intDayCounter < arTimeGridColumns.length; intDayCounter++){
                var srecTimeEntry = timesheetRecord.getSublistValue({
                    sublistId: 'timeitem',
                    fieldId: arTimeGridColumns[intDayCounter],
                    line: intLineCounter
                });
                if (srecTimeEntry !=' '){
                    var bBillable = timesheetRecord.getSublistValue({
                        sublistId: 'timeitem',
                        fieldId: 'isbillable',
                        line: intLineCounter
                    });
                    if (bBillable){
                        intSum += srcTimeEntry;
                     }
                }
             }
         }

         timesheetRecord.setValue({
             fieldId: 'custrecord_am_timesheet_billable_hours',
             value: intSum
         });
         return true;
    }
    return {
        saveRecord: timesheet_clientSaveRecord
    };
}); 

        

Related Topics

General Notices