From c754b3a5d3850decbe2e90d866cbcdf0d53844eb Mon Sep 17 00:00:00 2001 From: Chris Gunther Date: Sun, 30 May 2021 14:47:56 -0400 Subject: [PATCH] Properly extract external_id from advanced search results If you performed an advanced search specifying which columns to return and included externalId, you wouldn't be able to get the external_id from the resulting record via the usual external_id method. This now matches how internal_id is extracted. Prior to this, calls to external_id returned: ``` > record.external_id => {:@external_id=>"customer_1"} ``` Now, it returns: ``` > record.external_id => "customer_1" ``` --- lib/netsuite/support/search_result.rb | 4 ++++ spec/netsuite/actions/search_spec.rb | 2 ++ .../search/saved_search_joined_custom_customer.xml | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/netsuite/support/search_result.rb b/lib/netsuite/support/search_result.rb index 901c46edf..bd7071a18 100644 --- a/lib/netsuite/support/search_result.rb +++ b/lib/netsuite/support/search_result.rb @@ -89,6 +89,10 @@ def initialize(response, result_class, credentials) record[:basic][:internal_id] = record[:basic][:internal_id][:@internal_id] end + if record[:basic][:external_id] + record[:basic][:external_id] = record[:basic][:external_id][:@external_id] + end + result_wrapper = result_class.new(record.delete(:basic)) result_wrapper.search_joins = record results << result_wrapper diff --git a/spec/netsuite/actions/search_spec.rb b/spec/netsuite/actions/search_spec.rb index a3cbfea04..2f0abbec4 100644 --- a/spec/netsuite/actions/search_spec.rb +++ b/spec/netsuite/actions/search_spec.rb @@ -168,6 +168,8 @@ expect(search.results.size).to eq(2) expect(search.current_page).to eq(1) + expect(search.results.first.internal_id).to eq('123') + expect(search.results.first.external_id).to eq('456') expect(search.results.first.alt_name).to eq('A Awesome Name') expect(search.results.last.email).to eq('alessawesome@gmail.com') end diff --git a/spec/support/fixtures/search/saved_search_joined_custom_customer.xml b/spec/support/fixtures/search/saved_search_joined_custom_customer.xml index 490270e97..68b3fa4d5 100644 --- a/spec/support/fixtures/search/saved_search_joined_custom_customer.xml +++ b/spec/support/fixtures/search/saved_search_joined_custom_customer.xml @@ -16,6 +16,12 @@ + + + + + + A Awesome Name @@ -84,4 +90,4 @@ - \ No newline at end of file +