How can I get the current open Account Posting per...
# ask-stanley-ai
s
How can I get the current open Account Posting period using SuiteScript 2.1?
c
AI generated answer (using internal Slack threads):
To get the current open Account Posting period using SuiteScript 2.1, you can perform a search on the
accountingperiod
record. Here is a sample code snippet:
Copy code
javascript
var search = require('N/search');

function getCurrentOpenPeriod() {
    var periodSearch = search.create({
        type: search.Type.ACCOUNTING_PERIOD,
        filters: [
            ['isquarter', <http://search.Operator.IS|search.Operator.IS>, false],
            'AND',
            ['isyear', <http://search.Operator.IS|search.Operator.IS>, false],
            'AND',
            ['startdate', search.Operator.ON_OR_BEFORE, 'today'],
            'AND',
            ['enddate', search.Operator.ON_OR_AFTER, 'today'],
            'AND',
            ['alllocked', <http://search.Operator.IS|search.Operator.IS>, false],
            'AND',
            ['closed', <http://search.Operator.IS|search.Operator.IS>, false]
        ],
        columns: ['periodname']
    });

    var searchResult = periodSearch.run().getRange({start: 0, end: 1});
    if (searchResult.length > 0) {
        return searchResult[0].getValue({name: 'periodname'});
    } else {
        return null;
    }
}
This function will return the name of the current open accounting period. If no open period is found, it will return
null
. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.872309327
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842674196
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.837811768
Please provide your feedback on this answer.