Skip to content

Commit

Permalink
Properly extract external_id from advanced search results (#478)
Browse files Browse the repository at this point in the history
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"
```
  • Loading branch information
cgunther authored May 31, 2021
1 parent 33594f4 commit ece6f61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/netsuite/support/search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/netsuite/actions/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<platformCore:searchRowList>
<platformCore:searchRow xmlns:listRel="urn:relationships_2012_1.lists.webservices.netsuite.com" xsi:type="listRel:CustomerSearchRow">
<listRel:basic xmlns:platformCommon="urn:common_2012_1.platform.webservices.netsuite.com">
<platformCommon:internalId>
<platformCore:searchValue internalId="123"/>
</platformCommon:internalId>
<platformCommon:externalId>
<platformCore:searchValue externalId="456"/>
</platformCommon:externalId>
<platformCommon:altName>
<platformCore:searchValue>A Awesome Name</platformCore:searchValue>
</platformCommon:altName>
Expand Down Expand Up @@ -84,4 +90,4 @@
</platformCore:searchResult>
</searchResponse>
</soapenv:Body>
</soapenv:Envelope>
</soapenv:Envelope>

0 comments on commit ece6f61

Please sign in to comment.