Examples

CRUD Operations

# get a customer
customer =NetSuite::Records::Customer.get(:internal_id => 4)
customer.is_person
# orNetSuite::Records::Customer.get(4)
# get a list of customers
customers =NetSuite::Records::Customer.get_list(:list => [4, 5, 6])
# randomly assign a task
customer_support_reps = [12345, 12346]
task =NetSuite::Records::Task.new(
:title => 'Take Care of a Customer',
:assigned => NetSuite::Records::RecordRef.new(internal_id: customer_support_reps.sample),
:due_date => DateTime.now +1,
:message => "Take care of this"
)
task.add
# this will only work on OS X, open a browser to the record that was just created`open https://system.sandbox.netsuite.com/app/crm/calendar/task.nl?id=#{invoice.internal_id}`# update a field on a record
task.update(message:'New Message')
# delete a record
task.delete
# refresh/reload a record (helpful after adding the record for the first time)
task.reload
# using get_select_value with a standard recordNetSuite::Records::BaseRefList.get_select_value(
recordType:'serviceSaleItem',
field:'taxSchedule'
)
# get options for a custom sublist field (i.e. transaction column fields)NetSuite::Records::BaseRefList.get_select_value(
field:'custcol69_2',
sublist:'itemList',
recordType:'salesOrder'
)
# output names of options available for a custom field
options =NetSuite::Records::BaseRefList.get_select_value(
field:'custbody_order_source',
recordType:'invoice'
)
options.base_refs.map(&:name)

Custom Records & Fields

# updating a custom field list on a record# you need to push ALL the values of ALL of the custom fields that you want set on the record# you can't just push the values of the fields that you want to update: all of the values of# other fields will then fall back to their default values
contact =NetSuite::Records::Contact.get(12345)
contact.custom_field_list.custentity_alistfield = { internal_id:1 }
contact.custom_field_list.custentity_abooleanfield =true
contact.update(custom_field_list: contact.custom_field_list)
# getting a custom record
record =NetSuite::Records::CustomRecord.get(
# custom record typetype_id:10,
# reference to instance of the custom record typeinternal_id:100
)
# getting a list of custom records
records =NetSuite::Records::CustomRecord.get_list(
# netsuite internalIDslist: [1,2,3],
# only needed for a custom recordtype_id:1234
)
# adding a custom record
record =NetSuite::Records::CustomRecord.new
record.rec_type =NetSuite::Records::CustomRecord.new(internal_id:10)
record.custom_field_list.custrecord_locationstate ="New Jersey"
record.add
# updating a custom record
record =NetSuite::Records::CustomRecord.new(internal_id:100)
record.custom_field_list.custrecord_locationstate ="New Jersey"
record.update(custom_field_list: record.custom_field_list, rec_type:NetSuite::Records::CustomRecord.new(internal_id:10))
# using get_select_value with a custom recordNetSuite::Records::BaseRefList.get_select_value(
field:'custrecord_something',
customRecordType: {
'@internalId' => 10,
'@xsi:type' => 'customRecord'
}
)