Skip to content

Commit ece6f61

Browse files
authored
Properly extract external_id from advanced search results (#478)
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" ```
1 parent 33594f4 commit ece6f61

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/netsuite/support/search_result.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def initialize(response, result_class, credentials)
8989
record[:basic][:internal_id] = record[:basic][:internal_id][:@internal_id]
9090
end
9191

92+
if record[:basic][:external_id]
93+
record[:basic][:external_id] = record[:basic][:external_id][:@external_id]
94+
end
95+
9296
result_wrapper = result_class.new(record.delete(:basic))
9397
result_wrapper.search_joins = record
9498
results << result_wrapper

spec/netsuite/actions/search_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@
168168

169169
expect(search.results.size).to eq(2)
170170
expect(search.current_page).to eq(1)
171+
expect(search.results.first.internal_id).to eq('123')
172+
expect(search.results.first.external_id).to eq('456')
171173
expect(search.results.first.alt_name).to eq('A Awesome Name')
172174
expect(search.results.last.email).to eq('[email protected]')
173175
end

spec/support/fixtures/search/saved_search_joined_custom_customer.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
<platformCore:searchRowList>
1717
<platformCore:searchRow xmlns:listRel="urn:relationships_2012_1.lists.webservices.netsuite.com" xsi:type="listRel:CustomerSearchRow">
1818
<listRel:basic xmlns:platformCommon="urn:common_2012_1.platform.webservices.netsuite.com">
19+
<platformCommon:internalId>
20+
<platformCore:searchValue internalId="123"/>
21+
</platformCommon:internalId>
22+
<platformCommon:externalId>
23+
<platformCore:searchValue externalId="456"/>
24+
</platformCommon:externalId>
1925
<platformCommon:altName>
2026
<platformCore:searchValue>A Awesome Name</platformCore:searchValue>
2127
</platformCommon:altName>
@@ -84,4 +90,4 @@
8490
</platformCore:searchResult>
8591
</searchResponse>
8692
</soapenv:Body>
87-
</soapenv:Envelope>
93+
</soapenv:Envelope>

0 commit comments

Comments
 (0)