Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accessing custom field values returned in advanced search results #480

Merged
merged 2 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/netsuite/records/custom_field_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ def extract_custom_field(custom_field_data)
attrs = custom_field_data.clone
type = (custom_field_data[:"@xsi:type"] || custom_field_data[:type])

if type == "platformCore:SelectCustomFieldRef"
case type
when "platformCore:SelectCustomFieldRef", "platformCore:SearchColumnSelectCustomField"
attrs[:value] = CustomRecordRef.new(custom_field_data[:value])
elsif type == 'platformCore:MultiSelectCustomFieldRef'
when 'platformCore:MultiSelectCustomFieldRef', 'platformCore:SearchColumnMultiSelectCustomField'
# if there is only a single selection, `:value` will be hash not an array
attrs[:value] = if custom_field_data[:value].is_a?(Array)
custom_field_data[:value]
Expand Down
23 changes: 19 additions & 4 deletions lib/netsuite/support/search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ def initialize(response, result_class, credentials)
record_list = [record_list] unless record_list.is_a?(Array)

record_list.each do |record|
# TODO because of customFieldList we need to either make this recursive
# or handle the customFieldList as a special case

record.each_pair do |search_group, search_data|
# skip all attributes: look for :basic and all :xxx_join
next if search_group.to_s.start_with?('@')
Expand All @@ -63,7 +60,25 @@ def initialize(response, result_class, credentials)
# all return values are wrapped in a <SearchValue/>
# extract the value from <SearchValue/> to make results easier to work with

if v.is_a?(Hash) && v.has_key?(:search_value)
if k == :custom_field_list
# Here's an example of a response

# <platformCommon:customFieldList>
# <platformCore:customField internalId="1756" scriptId="custitem_stringfield" xsi:type="platformCore:SearchColumnStringCustomField">
# <platformCore:searchValue>sample string value</platformCore:searchValue>
# </platformCore:customField>
# <platformCore:customField internalId="1713" scriptId="custitem_apcategoryforsales" xsi:type="platformCore:SearchColumnSelectCustomField">
# <platformCore:searchValue internalId="4" typeId="464"/>
# </platformCore:customField>
# </platformCommon:customFieldList>

custom_field_list = v.fetch(:custom_field)
custom_field_list = [custom_field_list] unless custom_field_list.is_a?(Array)
record[search_group][k][:custom_field] = custom_field_list.map do |custom_field|
custom_field[:value] = custom_field.fetch(:search_value)
custom_field
end
elsif v.is_a?(Hash) && v.has_key?(:search_value)
# Here's an example of a record ref and string response

# <platformCommon:entity>
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 @@ -171,6 +171,8 @@
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.first.custom_field_list.custitem_stringfield.value).to eq('sample string value')
expect(search.results.first.custom_field_list.custitem_apcategoryforsales.value.internal_id).to eq('4')
expect(search.results.last.email).to eq('[email protected]')
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
<platformCommon:phone>
<platformCore:searchValue>444-444-4444</platformCore:searchValue>
</platformCommon:phone>
<platformCommon:customFieldList>
<platformCore:customField internalId="1756" scriptId="custitem_stringfield" xsi:type="platformCore:SearchColumnStringCustomField">
<platformCore:searchValue>sample string value</platformCore:searchValue>
</platformCore:customField>
<platformCore:customField internalId="1713" scriptId="custitem_apcategoryforsales" xsi:type="platformCore:SearchColumnSelectCustomField">
<platformCore:searchValue internalId="4" typeId="464"/>
</platformCore:customField>
</platformCommon:customFieldList>
</listRel:basic>
<listRel:contactJoin xmlns:platformCommon="urn:common_2012_1.platform.webservices.netsuite.com">
<platformCommon:email>
Expand Down