Home > Enterprise >  Access value from a Netsuite hash, Enumerator
Access value from a Netsuite hash, Enumerator

Time:01-04

Hi I am trying to extract a value from a Netsuite hash inside custom fields, and some others, which typically look like this - `

"custbody_delivery_ticket_number"=>
 {
 "script_id"=>"custbody_delivery_ticket_number", 
 "internal_id"=>"2701", 
 "type"=>"platformCore:DateCustomFieldRef", 
 "attributes"=> {
 "value"=>"123abc"
 }

}` and want the value of it inside of attributes.

Have tried many different ways, but one in particular -

 delivery_ticket_number: "#{netsuite_sales_orders.custom_field_list.custom_fields.select['custbody_nef_meter_ticket_number']['attributes']['value']}", 

throws error for class Enumerator, NoMethodError: undefined method `[]' for #Enumerator:0x00005589ec778730 which indicates may be getting close, but doing something wrong.

If anyone has any idea how to get values from these kind of hashes?

(Am told by the system admin that it is the correct custbody identifier)

Many Thanks

CodePudding user response:

Eventually fixed this, grabbing Netsuite custom fields with a select of script_id by name,and map as below:

delivery_date:netsuite_sales_order.custom_fields_list.custom_fields.select { |field| field.script_id == 'custbody_delivery_date' }.map { |field| field.value }.first

First selecting the script_id by unique name, then mapping to the value. Was able to get any custom field like this, preferable as they can move and might not have the same index if use an index to grab them, fetching an incorrect value. This way ensures getting the correct data even if the item is moved up or down in the custom fields list.

Thanks for everyones help!

  • Related