Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active April 29, 2017 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/1144cfe52172bbefb45599047f3fd332 to your computer and use it in GitHub Desktop.
Save iloveitaly/1144cfe52172bbefb45599047f3fd332 to your computer and use it in GitHub Desktop.
Example of closing a SalesOrder with the NetSuite SuiteTalk API
# Description: Example of closing a SalesOrder with the NetSuite SuiteTalk API
# Author: <mike@suitesync.io>
def close_sales_order(ns_order_id)
# If you want to pull the order associated with an invoice `ns_order_id = ns_invoice.created_from.internal_id`
ns_order = NetSuite::Utilities.get_record(NetSuite::Records::SalesOrder, ns_order_id)
# http://mikebian.co/how-to-close-a-netsuite-salesorder-using-suitetalk/
# NOTE: it's impossible to cancel an order once it has been approved
# after an order has been approved, you'll need to close it
ns_order.item_list.items.each do |item|
item.is_closed = true
end
result = NetSuite::Utilities.backoff { ns_order.update(item_list: ns_order.item_list) }
if !result
raise "error closing order #{ns_order.errors}"
end
ns_order
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment