ANS-1526 · SUITESCRIPT DEVELOPMENT

How to Programmatically Access NetSuite Accounting Periods with SuiteScript 2.x

NetSuite's "accountingperiod" record, though not always explicitly documented, can be programmatically accessed and searched using SuiteScript 2.x to retrieve financial period details for custom solutions.

Short answer

Yes, the "accountingperiod" record is fully accessible via SuiteScript for read and search operations, enabling developers to retrieve details about posting periods. Though not always explicitly listed, it supports standard search functionalities. Current development should utilize SuiteScript 2.x's N/search module for these operations, ensuring compatibility and best practices.

Scenario

NetSuite developers often need to programmatically interact with financial periods to automate processes or build custom reports. A common question arises regarding the accessibility of the "accountingperiod" record through SuiteScript, especially when it may not be explicitly listed in all SuiteScript Supported Records documentation. This can lead to uncertainty about how to search for specific posting periods, such as the current month's period, within a script.

Solution

The "accountingperiod" record is indeed exposed through SuiteScript for read and search operations, even if it is not explicitly listed in all SuiteScript Supported Records documentation. To programmatically search for specific posting periods, such as the current month's period, developers should utilize SuiteScript 2.x, which is the current and recommended version for NetSuite development.The following SuiteScript 2.x code snippet demonstrates how to search for the posting period of the current month, specifically excluding quarter and fiscal year periods:

javascript/** * @NApiVersion 2.x * @NModuleScope SameAccount */define(['N/search'], function(search) {    // Define filters for the accounting period search    var periodFilters = [        search.createFilter({            name: 'enddate',            operator: search.Operator.WITHIN,            values: ['thismonth']        }),        search.createFilter({            name: 'isquarter',            operator: search.Operator.IS,            values: ['F']        }),        search.createFilter({            name: 'isyear',            operator: search.Operator.IS,            values: ['F']        })    ];    // Create and run the search for accounting periods    // This example retrieves the first matching period.    var periodResults = search.create({        type: search.Type.ACCOUNTING_PERIOD,        filters: periodFilters,        columns: ['periodname', 'startdate', 'enddate'] // Example columns to retrieve    }).run().getRange({ start: 0, end: 1 });    // To process results, you might iterate:    // if (periodResults && periodResults.length > 0) {    //     var currentMonthPeriod = periodResults[0];    //     log.debug('Current Month Period Name', currentMonthPeriod.getValue('periodname'));    //     log.debug('Start Date', currentMonthPeriod.getValue('startdate'));    //     log.debug('End Date', currentMonthPeriod.getValue('enddate'));    // }});

This snippet illustrates the use of the N/search module to define filters and execute a search against the "accountingperiod" record type. The specified filters ensure that only the posting period for the current month, which is neither a quarter nor a fiscal year, is returned.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant