README.md in netsuite-0.2.6 vs README.md in netsuite-0.3.0

- old
+ new

@@ -1,5 +1,7 @@ +[![Build Status](https://travis-ci.org/NetSweet/netsuite.svg)](https://travis-ci.org/NetSweet/netsuite) + # NetSuite Ruby SuiteTalk Gem * This gem will act as a wrapper around the NetSuite SuiteTalk WebServices API. Wow, that is a mouthful. * The gem does not cover the entire API, only the subset that we have found useful to cover so far. * Extending the wrapper is pretty simple. Check out the [contribution help doc](https://github.com/RevolutionPrep/netsuite/wiki/Contributing-to-the-Supported-NetSuite-API) @@ -64,18 +66,23 @@ end ``` ### Examples +#### CRUD Operations + ```ruby -# retrieve a customer +# get a customer customer = NetSuite::Records::Customer.get(:internal_id => 4) customer.is_person # or NetSuite::Records::Customer.get(4).is_person +# 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', @@ -89,10 +96,60 @@ # 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}` task.update :message => 'New Message' +# using get_select_value with a custom record +NetSuite::Records::BaseRefList.get_select_value( + field: 'custrecord_something', + customRecordType: { + '@internalId' => 10, + '@xsi:type' => 'customRecord' + } +) + +# updating a custom field list +# 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 type + type_id: 10, + # reference to instance of the custom record type + internal_id: 100 +) + +# getting a list of custom records +records = NetSuite::Records::CustomRecord.get_list( + # netsuite internalIDs + list: [1,2,3], + # only needed for a custom record + type_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)) + +``` + +#### Searching + +```ruby # basic search search = NetSuite::Records::Customer.search({ basic: [ { field: 'companyName', @@ -102,12 +159,21 @@ ] }) `open https://system.netsuite.com/app/common/entity/custjob.nl?id=#{search.results.first.internal_id}` +# searching for custom records +NetSuite::Records::CustomRecord.search(basic: [ +{ + field: 'recType', + operator: 'is', + # custom record type + value: NetSuite::Records::CustomRecordRef.new(:internal_id => 10), +}]).results + # advanced search building on saved search -search = NetSuite::Records::Customer.search({ +NetSuite::Records::Customer.search({ saved: 500, # your saved search internalId basic: [ { field: 'entityId', operator: 'hasKeywords', @@ -125,24 +191,29 @@ field: 'customFieldList', value: [ { field: 'custentity_acustomfield', operator: 'anyOf', - # type is needed for multiselect fields + # type is needed for all search fields type: 'SearchMultiSelectCustomField', value: [ NetSuite::Records::CustomRecordRef.new(:internal_id => 1), NetSuite::Records::CustomRecordRef.new(:internal_id => 2), ] - } + }, + { + field: 'custbody_internetorder', + type: 'SearchBooleanCustomField', + value: true + } ] } ] -}) +}).results -# advanced search from stratch -search = NetSuite::Records::Transaction.search({ +# advanced search from scratch +NetSuite::Records::Transaction.search({ criteria: { basic: [ { field: 'type', operator: 'anyOf', @@ -169,11 +240,10 @@ # "2013-07-30T22:00:00.000-07:00" ] } ], - # equivilent to the 'Account' label in the GUI accountJoin: [ { field: 'internalId', operator: 'noneOf', @@ -226,11 +296,11 @@ }, preferences: { page_size: 10 } -}) +}).results # basic search with pagination / SearchMorewithId search = NetSuite::Records::Customer.search( criteria: { basic: [ @@ -249,61 +319,69 @@ search.results_in_batches do |batch| puts batch.map(&:internal_id) end +# item search +NetSuite::Records::InventoryItem.search({ + criteria: { + basic: [ + { + field: 'type', + operator: 'anyOf', + type: 'SearchEnumMultiSelectField', + value: [ + '_inventoryItem', + + # note that the naming conventions aren't consistent: AssemblyItem != _assemblyItem + '_assembly' + ] + }, + { + field: 'isInactive', + value: false + } + ] + } +}).results.first + +# set body_fields_only = false to include the majority of lists associated with records in the XML response +# Some lists you just can't include with searches (a customer's AddressBookList, for example) + +# In order to get the full record data for those records whose lists aren't included when body_fields_only = false +# you will have to run a get_list call on the resulting internalIds returned from the search you've executed + +search = NetSuite::Records::File.search({ + preferences: { + body_fields_only: false, + page_size: 20 + } +}) + +search.results_in_batches do |batch| + batch.each do |file| + next unless file.file_type == "_JAVASCRIPT" + puts Base64.decode64(file.content) + end +end +``` + +#### Non-standard Operations + +```ruby # making a call that hasn't been implemented yet NetSuite::Configuration.connection.call :get_customization_id, message: { 'platformMsgs:customizationType' => { '@getCustomizationType' => 'customRecordType'}, 'platformMsgs:includeInactives' => 'false' } server_time_response = NetSuite::Configuration.connection.call :get_server_time server_time_response.body[:get_server_time_response][:get_server_time_result][:server_time] -# using get_select_value with a custom record -NetSuite::Records::BaseRefList.get_select_value( - field: 'custrecord_something', - customRecordType: { - '@internalId' => 10, - '@xsi:type' => 'customRecord' +# getting a list of states +states = NetSuite::Configuration.connection.call(:get_all, message: { + 'platformCore:record' => { + '@recordType' => 'state' } -) - -# updating a custom field list -# 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) - -# the getList operation -NetSuite::Records::CustomRecord.get_list( - # netsuite internalIDs - list: [1,2,3], - # only needed for a custom record - type_id: 1234 -).each do |record| - # do your thing... -end - -# getting a custom record -record = NetSuite::Records::CustomRecord.get( - # custom record type - type_id: 10, - # reference to instance of the custom record type - internal_id: 100 -) - -# 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)) +}) +states.to_array.first[:get_all_response][:get_all_result][:record_list][:record].map { |r| { country: r[:country], abbr: r[:shortname], name: r[:full_name] } } ```