Payroll Batch
This record is available only for SuitePeople U.S. Payroll customers. For more information, see SuitePeople Overview.
For help working with this record in the UI, see Creating a Payroll Batch.
The internal ID of this record is payrollbatch
.
For information about scripting with this record in SuiteScript, see the following help topics:
See the SuiteScript Records Browser for all internal IDs associated with this record.
For information about using the SuiteScript Records Browser, see Working with the SuiteScript Records Browser in the NetSuite Help Center.
Supported Script Types
The payroll batch record is scriptable in both client and server SuiteScript.
Supported Functions
The payroll batch record is fully scriptable, which means that the record can be created, updated, copied, deleted and searched using SuiteScript.
Usage Notes
Be aware of the following:
-
After a payroll batch is created, it is submitted twice: one time to calculate and again to commit.
-
To calculate a payroll batch, after the batch is submitted, it needs to be reloaded until one of the following statuses is generated: calculated, committed, or error.
-
If you are calculating and committing a large amount of data, you should write a loop to recheck the status of the payroll batch. Refer to the following table for more details.
Payroll Batch Status |
Value |
Description |
---|---|---|
|
A |
A new payroll batch has been created. |
|
B |
A payroll batch has been calculated. |
|
C |
A payroll batch may have been calculated previously, or it is a newly created batch with some paychecks added or calculated. |
|
D |
Payroll is about to be committed. |
|
E |
Payroll is committed for processing by payroll service, but some records need to be created in NetSuite. |
|
F |
Payroll is committed. |
|
P |
Payroll batch is completed. |
|
R |
Payroll batch is reversed. |
|
X |
Error occurred in payroll batch. |
Code Samples
The following sample shows how to create a payroll batch and perform other basic tasks. It also includes how to add an employee to a payroll batch. For more information, see Payroll Batch Employee.
require(["N/record"], function (record)
{
var payrollbatch = record.create({
type: 'payrollbatch',
isDynamic: true
});
payrollbatch.setValue({
fieldId: 'offcycle',
value: false
});
payrollbatch.setValue({
fieldId: 'payfrequency',
value: '52'
});
payrollbatch.setValue({
fieldId: 'periodending',
value: new Date('6/15/2020')
});
var recId = payrollbatch.save();
// Add employees to the payroll batch
// In most cases, you would iterate through the addmorepayeesmachine to find the employees you would add to the batch
var addemp = payrollbatch.load({
type: 'payrollbatchaddemployees',
id: id,
defaultValues: 'true'
});
addemp.setSublistValue({
sublistId: 'addmorepayeesmachine',
fieldId: 'payemp',
line: 1,
value: 'T'
});
var recId2 = addemp.save();
//Submit the record to be calculated
payrollbatch = record.load({
type: 'payrollbatch',
id: id,
defaultValues: 'false'
});;
var recId3 = payrollbatch.save();
//Check the status of the record to ensure that calculating is complete before proceeding
do {
payrollbatch = record.load({
type: 'payrollbatch',
id: id,
defaultValues: 'false'
});
status = payrollbatch.getValue({
fieldId: 'status'
});
} while ( !(status ==='B' || status === 'E' || status ==='X') );
//Set the flag to commit the payroll batch
if (status ==='B') {
payrollbatch.setValue({
fieldId: 'commit',
value: 'T'
});
}
//Commit
var recId3 = payrollbatch.save();
do {
payrollbatch = record.load({
type: 'payrollbatch',
id: id,
defaultValues: 'false'
});
status = payrollbatch.getValue({
fieldId: 'status'
});
} while ( !(status === 'F' || status === 'E' || status === 'X') );
});