From 927ab5d3e10a2cf5c71011eab05c5b02fce92cdd Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Thu, 16 Mar 2023 15:45:44 -0400 Subject: [PATCH 1/3] dont crash if suitetalk returns empty --- lib/netsuite/support/search_result.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/netsuite/support/search_result.rb b/lib/netsuite/support/search_result.rb index 2cd936c5f..2b7bd6549 100644 --- a/lib/netsuite/support/search_result.rb +++ b/lib/netsuite/support/search_result.rb @@ -48,7 +48,8 @@ def initialize(response, result_class, credentials) end elsif response.body.has_key? :search_row_list # advanced search results - record_list = response.body[:search_row_list][:search_row] + record_list = response.body[:search_row_list] + record_list = record_list ? record_list[:search_row] : [] record_list = [record_list] unless record_list.is_a?(Array) record_list.each do |record| From 785e2886fd2ba987e7ede538d388fb2c663907d8 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Wed, 22 Mar 2023 11:26:35 -0400 Subject: [PATCH 2/3] test for empty search_row_list as well --- spec/netsuite/support/search_result_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/netsuite/support/search_result_spec.rb b/spec/netsuite/support/search_result_spec.rb index 8ef2c32ef..de27847df 100644 --- a/spec/netsuite/support/search_result_spec.rb +++ b/spec/netsuite/support/search_result_spec.rb @@ -22,6 +22,23 @@ results = described_class.new(response, NetSuite::Actions::Search, {}).results expect(results).to eq [] end + + it 'returns empty search_row_list' do + response_body = { + :status => {:@is_success=>"true"}, + :total_records => "242258", + :page_size => "10", + :total_pages => "24226", + :page_index => "99", + :search_id => "WEBSERVICES_4132604_SB1_051620191060155623420663266_336cbf12", + :search_row_list => nil, + :"@xmlns:platform_core" => "urn:core_2016_2.platform.webservices.netsuite.com" + } + response = NetSuite::Response.new(body: response_body) + + results = described_class.new(response, NetSuite::Actions::Search, {}).results + expect(results).to eq [] + end end it 'handles a recordList with a single element' do From 53b02fdd2b0f6e71b0b9c1b293d233c9af56ef4e Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Thu, 11 Apr 2024 10:26:57 -0400 Subject: [PATCH 3/3] avoid mutating options passed to us since this makes nesting calls within NetSuite::Utilities.backoff very confusing --- lib/netsuite/actions/search.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/netsuite/actions/search.rb b/lib/netsuite/actions/search.rb index 51451b3b9..d51428f3a 100644 --- a/lib/netsuite/actions/search.rb +++ b/lib/netsuite/actions/search.rb @@ -6,7 +6,7 @@ class Search < AbstractAction def initialize(klass, options = { }) @klass = klass - @options = options + @options = options.dup end def class_name @@ -42,7 +42,7 @@ def request_body # columns is only needed for advanced search results columns = @options[:columns] || {} - criteria = @options[:criteria] || @options + criteria = @options[:criteria].dup || @options # TODO find cleaner solution for pulling the namespace of the record, which is a instance method namespace = if @klass.respond_to?(:search_class_namespace) @@ -114,6 +114,7 @@ def request_body # https://github.com/NetSweet/netsuite/commit/54d7b011d9485dad33504135dfe8153c86cae9a0#commitcomment-8443976 if NetSuite::Configuration.api_version < "2013_2" + h[element_name][:attributes!]['platformCore:customField'] = h[element_name][:attributes!]['platformCore:customField'].dup h[element_name][:attributes!]['platformCore:customField']['internalId'] = h[element_name][:attributes!]['platformCore:customField'].delete('scriptId') end