Marty Zigman Marty Zigman
Prolecto Labs Accelerator Templates

How To: Script to Automate NetSuite Journal Entries

Accounting NetSuite Technical

Tags: , , , ,

This article is relevant if you want to automate the creation of NetSuite journal entries and you are comfortable with basic scripting concepts.

SuiteScript Code Example for Creating Journal Entries

The following code example is the bare minimum script pattern to get a journal entry into NetSuite through SuiteScript.  This code snippet should sit inside a SuiteScript User Event or Client script definition.  I recommend using the SuiteScript Records Browser to help you with the specific journal entry API field references.

var Trx = new custBizObject();  // our custom business object holding important data
var Config = new custConfigObject(); //our custom configuration object for our app
var memo = 'script to create journal entry';

var je = nlapiCreateRecord('journalentry');
je.setFieldValue('trandate', nlapiDateToString(nlapiStringToDate(Trx.StatusDate)));
je.setFieldValue('currency', Config.CurrencyReference);
je.setFieldValue('exchangerate', Trx.mExchRate);

//create the line items; first work control account
je.selectNewLineItem('line');
je.setCurrentLineItemValue('line', 'account', Config.APDefault);
je.setCurrentLineItemValue('line', 'debit', RoundNumber(Trx.mQtyGross, 2));
je.setCurrentLineItemValue('line', 'entity', entityID);
je.setCurrentLineItemValue('line', 'memo', memo);
je.commitLineItem('line');

// now work the bank account
je.selectNewLineItem('line');
je.setCurrentLineItemValue('line', 'account', Config.BankAccount);
je.setCurrentLineItemValue('line', 'credit', RoundNumber(Trx.mQtyGross, 2));
je.setCurrentLineItemValue('line', 'entity', Trx.Receipient);
je.setCurrentLineItemValue('line', 'memo', memo);
je.commitLineItem('line');

return nlapiSubmitRecord(je, true, false);		//return JE transaction number

Related Articles

  1. NetSuite Up Close: Custom GL Lines Plug-in to Reclass General Ledger Postings

Get Help

NetSuite is a great application development environment.  If you need help innovating on the platform, contact us.

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

26 thoughts on “How To: Script to Automate NetSuite Journal Entries

  1. Mike Robbins says:

    Thanks for this, Marty. I’ve noticed here and other places that people often use the
    nlapiDateToString(nlapiStringToDate(Trx.StatusDate)

    pattern when working with dates in SuiteScript. So I’m curious why that is. If I need a date and it’s already a date, why jump through the hoops? What’s the advantage?

  2. Mike Robbins says:

    sorry, meant if i need a string and it’s already a string….

  3. Marty Zigman says:

    HI Mike,

    Here is the reason why, as I understand it. The NetSuite date data is not a Javascript Date format. It is an Oracle date format. Hence, it is effectively a string in relationship to Javascript. So, if you want to do Javascript date math, you need to turn the string into a Javascript Date, and then when it is time to put it back in the database, you need to turn it back to a format NetSuite understands.

    Yet, that doesn’t seem to answer the question, does it? In this case, it looks like it is going through an unnecessary loop — just as you suggested. Let me explore this on my next code effort to produce a better explanation.

  4. praveen sharma says:

    hi sir,
    how to get particular date tranaction using filter search.
    ex- i want all invoices we are created 25 for every month.

  5. Marty Zigman says:

    Hello Praveen,

    Here is a generic function to get the accounting period which is keying on the date. The pattern can show you how to setup multiple criteria objects which is what you will need to do to create a Transaction search of type Invoice. Remember, you need to be careful when working with dates in NetSuite. Be sure to translate your JavaScript dates via nlapiDateToString functions.

    function Get_Accounting_Period(transdate){

    //set search criteria: find all periods that date falls into that aren’t quarter, year or adjustment
    var id = null;
    var filters = new Array();
    filters[0] = new nlobjSearchFilter(‘startdate’, null, ‘onorbefore’, transdate);
    filters[1] = new nlobjSearchFilter(‘enddate’, null, ‘onorafter’, transdate);
    filters[2] = new nlobjSearchFilter(‘isquarter’, null, ‘is’, ‘F’);
    filters[3] = new nlobjSearchFilter(‘isyear’, null, ‘is’, ‘F’);
    //filters[3] = new nlobjSearchFilter(‘isadjust’, null, ‘is’, ‘F’);

    var columns = new Array();
    columns[0] = new nlobjSearchColumn(‘isadjust’);

    var recordtype = ‘accounting’ + ‘period’;
    var searchresults = nlapiSearchRecord(recordtype, null, filters, columns);
    for (var i = 0; searchresults != null && i < searchresults.length; i++) {
    id = searchresults[i].getId();
    }
    if (!id){
    return null;
    }

    nlapiLogExecution('DEBUG', 'Get_Accounting_Period Found accounting periods transdate|id:', transdate + '|' + id);
    return id;
    }

    Marty

  6. shick says:

    hey sir i am a student. can i please get a sample code from you on how to code the journal entries and will also give its financial statement or income statement after i put my transaction. i will be glad if you reply sir. 🙁 you will be my life saver 🙁

  7. shick says:

    btw i am using java script please answer me 🙁

  8. Marty Zigman says:

    Hello Shick,

    The answer is all there for you. I recommend some basis SuiteScript experience. Here is a tutorial.

  9. Lee says:

    hii
    can u help me out with suiteGL custom gl lines scripting.

    some sample codes

    i checked in netsuite helpcenter, i need something better than that

  10. Marty Zigman says:

    I recommend reviewing all my technical articles to find code examples.

  11. Hitesh says:

    Hi Marty,
    Thanks for your helpful information.
    I am trying to update journal entry using Suite talk API it is giving error-:
    Journal Entries can have a maximum of 1000 lines

    Is there any way to update journal entry have more than 1000 rows
    Thanks,
    Hitesh Kumar.

  12. Marty Zigman says:

    Hi Hitesh,

    That may indeed be a limit. In general, I advise our clients to be careful with any transaction object that has more than 1,000 lines. I usually invent patterns to summarize or think about the problem differently to help records be more manageable. I recommend going to NetSuite Support to get the official word on limitations.

    Marty

  13. Hitesh says:

    Hi Marty,

    JE sub list is keyed or not keyed?

    I am trying to update a single line but getting error for line.line,but i am able to add new line.

    Thanks Hitesh,

  14. Marty Zigman says:

    Have you tried to use the nlapiSelectLineItem() function to get on the line you care about first?

    marty

  15. HItesh Kumar says:

    Hi Marty.

    I am using the suite talk API with c#,and I get the the line number for every line but when i try to update particular line by providing the line number, I am getting the error.

    Thanks,
    Hitesh.

  16. Real Drouin says:

    I like the basic script a lot. I see that it’s written with Suitescript 1. I have to do something similar today.

    Would you recommand to start with you script or redo it entirely with Suitescrip 2 ?

    Thanks
    Real

  17. Marty Zigman says:

    Hi Real,

    At this point, we only do work in SuiteScript 2.0 unless we are in maintenance on previous work. I’ll get more code examples in future articles.

    Marty

  18. Dinesh says:

    Hi Marty,

    I am trying to Create the Advance Intercompany journals using Suitescript 2.0 but it is throwing the error as Please enter value(s) for: Account even i am passing the account for Line level.

    But it is working when we use suitescript 1.0.

    Please help me on this.

  19. Marty Zigman says:

    Hello Dinesh,

    Can you provide a pointer to your code? Else, let’s have a conversation here:
    https://www.prolecto.com/contact-us/

    Marty

  20. Grant Miller says:

    Was this resolved? I am having the same issue.
    Trying to create the Advance Intercompany journals using Suitescript 2.1 but it is throwing the error as Please enter value(s) for: Account even i am passing the account for Line level.

  21. Grant Miller says:

    Found out the answer to my question Feb.27 2024. This error was completely misleading. The issue was that on the sublist line field id I was coding -‘subsidiary’, when it fact the field name for AICJ is fieldId: ‘linesubsidiary’. The Records Browser confirmed this, and as soon as I changed the name, bingo, everything worked. By the way, NetSuite AICJ sample code uses ‘subsidiary’ for the field id…. just needed to point that out. Hope this helps someone struggling with this.

Leave a Reply

Your email address will not be published. Required fields are marked *