Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Created July 17, 2017 21:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/92a776ad6d144e16d3428d6669a40b28 to your computer and use it in GitHub Desktop.
Save iloveitaly/92a776ad6d144e16d3428d6669a40b28 to your computer and use it in GitHub Desktop.
Example of creating a NetSuite Journal Entry using the SuiteTalk API
# Michael Bianco <mike@suitesync.io>
# Description: Example of creating a journal entry using the SuiteTalk API
#
# Usage:
#
# export NETSUITE_EMAIL=user@company.com NETSUITE_PASSWORD=password NETSUITE_ACCOUNT= NETSUITE_APPLICATION_ID=
# gem install netsuite
# ruby create_netsuite_journal_entry.rb
#
require 'netsuite'
NetSuite.configure do
reset!
# NOTE a recent API version should be used for journal entry creation: many options are not available
# when using older API versions
api_version '2016_2'
read_timeout 60 * 3
silent ENV['NETSUITE_SILENT'].nil? || ENV['NETSUITE_SILENT'] == 'true'
email ENV['NETSUITE_EMAIL']
password ENV['NETSUITE_PASSWORD']
account ENV['NETSUITE_ACCOUNT']
soap_header({
'platformMsgs:preferences' => {
'platformMsgs:ignoreReadOnlyFields' => true,
},
# https://system.na1.netsuite.com/app/common/integration/integrapplist.nl
'platformMsgs:ApplicationInfo' => {
'platformMsgs:applicationId' => ENV['NETSUITE_APPLICATION_ID']
}
})
end
# https://system.na1.netsuite.com/app/accounting/account/accounts.nl
ns_deferred_income_account_id = 60
ns_income_account_id = 61
revenue_amount = 100.0
# http://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_2/schema/record/journalentry.html
journal_entry = NetSuite::Records::JournalEntry.new(
external_id: "entry-#{Time.now.to_i}",
memo: "Manual Rev Rec",
# NOTE if you have multiple currencies, specify the currency that should be used
# https://system.na1.netsuite.com/app/common/multicurrency/currencylist.nl
# currency: { internal_id: 1 },
# NOTE if you have one, specify a tranDate in case the job creating the JE is delayed because of a NetSuite outage
# time should be passed to this helper as a UTC0 unix timestamp
tran_date: NetSuite::Utilities.normalize_time_to_netsuite_date(Time.now.utc.to_i),
# http://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_2/schema/other/journalentryline.html?mode=package
line_list: { line: [
{
account: { internal_id: ns_deferred_income_account_id },
debit: revenue_amount
},
{
account: { internal_id: ns_income_account_id },
credit: revenue_amount
}
] }
)
NetSuite::Utilities.backoff { journal_entry.upsert }
if NetSuite::Utilities.request_failed?(journal_entry)
puts "failed to create journal entry"
end
@viiicky
Copy link

viiicky commented May 24, 2018

Hey, following this script, I tried the same in Python, but facing some issue. Can you please help.
Here is the stackoverflow link of my question: https://stackoverflow.com/questions/50461876/netsuite-namespace-conflict-core-2017-2-platform-vs-accounting-2017-2-lists

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment