Skip to content

Commit

Permalink
Fetch external id from @objects if it doesn't exist in status array
Browse files Browse the repository at this point in the history
  • Loading branch information
aom committed Oct 7, 2019
1 parent aa17e2d commit 0382c36
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/netsuite/actions/add_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ def response_errors
end

def errors
errors = response_hash.select { |h| h[:status] && h[:status][:status_detail] }.map do |obj|
errors = response_hash.select { |h| h[:status] }.each_with_index.map do |obj, index|
error_obj = obj[:status][:status_detail]
next if error_obj.nil?
error_obj = [error_obj] if error_obj.class == Hash
errors = error_obj.map do |error|
NetSuite::Error.new(error)
end

[obj[:base_ref][:@external_id], errors]
external_id =
(obj[:base_ref] && obj[:base_ref][:@external_id]) ||
(@objects[index].respond_to?(:external_id) && @objects[index].external_id)
[external_id, errors]
end
Hash[errors]
end
Expand All @@ -84,10 +88,10 @@ def self.included(base)
module ClassMethods
def add_list(records, credentials = {})
netsuite_records = records.map do |r|
if r.kind_of?(self)
if r.is_a?(self)
r
else
self.new(r)
new(r)
end
end

Expand Down

0 comments on commit 0382c36

Please sign in to comment.