Module: NetSuite::Actions::UpsertList::Support::ClassMethods

Defined in:
lib/netsuite/actions/upsert_list.rb

Instance Method Summary collapse

Instance Method Details

#upsert_list(records, credentials = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/netsuite/actions/upsert_list.rb', line 89

def upsert_list(records, credentials = {})
  netsuite_records = records.map do |r|
    if r.kind_of?(self)
      r
    else
      self.new(r)
    end
  end

  response = NetSuite::Actions::UpsertList.call(netsuite_records, credentials)

  if response.success?
    response.body.map do |attr|
      record = netsuite_records.find do |r|
        r.external_id == attr[:@external_id]
      end

      record.instance_variable_set('@internal_id', attr[:@internal_id])
    end

    netsuite_records
  else
    false
  end
end