ANS-1558 · SUITESCRIPT DEVELOPMENT
How to Script NetSuite Next Bill Date Functionality During Sales Order Transformation
Automate the setting of the next bill date when transforming a sales order into an invoice or cash sale using SuiteScript 2.x.
Short answer
To utilize NetSuite's 'Next Bill' functionality via scripting, initialize the bill date during the sales order transformation process. This involves looking up the 'nextbilldate' from the sales order and passing it as a default value when creating the new transaction record (invoice or cash sale) using SuiteScript 2.x.
Scenario
Users need to programmatically set the bill date for transformed sales orders, specifically leveraging the 'Next Bill' functionality. This is crucial for automating billing processes where the bill date needs to align with a predefined schedule on the original sales order, ensuring accurate financial record-keeping.
Solution
To leverage the 'Next Bill' functionality through scripting, the bill date must be initialized during the sales order transformation process. This involves retrieving the 'nextbilldate' from the original sales order and passing it as a default value when creating the new transaction record (e.g., invoice or cash sale) using SuiteScript 2.x. The following SuiteScript 2.x example demonstrates this process. Ensure that the N/record and N/search modules are loaded in your script (e.g., via define statement in a SuiteScript 2.x module or script file).
javascript
var salesOrderId = 'xxx'; // Replace 'xxx' with the actual sales order internal ID
var nextBillDate = search.lookupFields({
type: search.Type.SALES_ORDER,
id: salesOrderId,
columns: ['nextbilldate']
}).nextbilldate;
var transformedRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: salesOrderId,
toType: record.Type.CASH_SALE, // Can also be record.Type.INVOICE
defaultValues: {
billdate: nextBillDate
}
});
transformedRecord.save();It is important to note that 'nextbilldate' is not directly documented as a standard body field but is available as a search column, which is why a lookup operation is necessary to retrieve its value.
Key considerations for implementation include:
This approach can be applied to sales orders without billing schedules, but additional validation logic may be beneficial to ensure a billing schedule is present if that is a requirement.
The target record type for the transformation can be either
record.Type.INVOICEorrecord.Type.CASH_SALE.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
