Last active
April 29, 2017 22:23
-
-
Save iloveitaly/1144cfe52172bbefb45599047f3fd332 to your computer and use it in GitHub Desktop.
Example of closing a SalesOrder with the NetSuite SuiteTalk API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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