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
Get Help
NetSuite is a great application development environment. If you need help innovating on the platform, contact us.
See Related Articles
- NetSuite Up Close: Custom GL Lines Plug-in to Reclass General Ledger Postings
- NetSuite Mass Update with SuiteScript to Write Off Invoices
- NetSuite Transaction Type Internal ID Numbers
- NetSuite SearchFilter Internal Transaction Type Codes
- NetSuite SearchFilter Internal Account Type Codes
- NetSuite SearchFilter Transaction Internal Status List
- Use Custom Logic to Drive NetSuite General Ledger Posting Accounts
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?
sorry, meant if i need a string and it’s already a string….
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.
hi sir,
how to get particular date tranaction using filter search.
ex- i want all invoices we are created 25 for every month.
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
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 🙁
btw i am using java script please answer me 🙁
Hello Shick,
The answer is all there for you. I recommend some basis SuiteScript experience. Here is a tutorial.
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
I recommend reviewing all my technical articles to find code examples.
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.
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
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,
Have you tried to use the nlapiSelectLineItem() function to get on the line you care about first?
marty
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.
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
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
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.
Hello Dinesh,
Can you provide a pointer to your code? Else, let’s have a conversation here:
https://www.prolecto.com/contact-us/
Marty
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.
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.