Search code examples
ruby-on-railsrubysavonnetsuite

Error when getting a transaction using Netsuite Ruby Gem - Savon::SOAPFault: (soapenv:Server.userException)


I'm using the netsuite ruby gem (https://github.com/RevolutionPrep/netsuite).

I talked to the founder of the gem and I'm using the correct way of grabbing a transaction: https://github.com/RevolutionPrep/netsuite/issues/52

In Gemfile:

gem 'netsuite'

I keep getting this when doing the transaction search:

1.9.3p448 :008 > search = NetSuite::Records::Transaction.get(3820)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
Savon::SOAPFault: (soapenv:Server.userException) org.xml.sax.SAXException: transaction is not a legal value for {urn:types.core_2013_2.platform.webservices.netsuite.com}RecordType

This gives the same error as well:

search = NetSuite::Records::Transaction.get(:internal_id => 3820)

This works:

def getAllTransactions
    #SearchStringField, searchValue

    t = Time.new 

    search = NetSuite::Records::Transaction.search({
        criteria: {
        basic: [
            {
                field: 'type',
                operator: 'anyOf',
                type: 'SearchEnumMultiSelectField',
                value: [ "_invoice" ]
            },
            {
                field: 'tranDate',
                operator: 'within',

                type: 'SearchDateField',
                value: [
                      Date.parse("12/1/2013").strftime("%Y-%m-%dT%H:%M:%S%z"),
                      Date.parse("#{t.month}/#{t.day}/#{t.year}").strftime("%Y-%m-%dT%H:%M:%S%z")
                    ]
            }
            ]
        }
    })

    search
end

And this works too:

NetSuite::Records::Customer.get(:internal_id => 3820)

These don't work:

1.9.3p448 :007 > customer = NetSuite::Records::Invoice.get(:internal_id => 7996) 
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
NetSuite::RecordNotFound: NetSuite::Records::Invoice with OPTIONS={:internal_id=>7996} could not be found
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/netsuite-0.2.0/lib/netsuite/actions/get.rb:73:in `get'
    from (irb):7
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:5:in `require'
    from script/rails:5:in `<main>'

1.9.3p448 :008 > customer = NetSuite::Records::SalesOrder.get(:internal_id => 7996)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
NetSuite::RecordNotFound: NetSuite::Records::SalesOrder with OPTIONS={:internal_id=>7996} could not be found
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/netsuite-0.2.0/lib/netsuite/actions/get.rb:73:in `get'
    from (irb):8
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:5:in `require'
    from script/rails:5:in `<main>'

1.9.3p448 :009 > customer = NetSuite::Records::CashSale.get(:internal_id => 7996)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)
NetSuite::RecordNotFound: NetSuite::Records::CashSale with OPTIONS={:internal_id=>7996} could not be found
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/netsuite-0.2.0/lib/netsuite/actions/get.rb:73:in `get'
    from (irb):9
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/pkatepalli/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:5:in `require'
    from script/rails:5:in `<main>'

this works:

1.9.3p448 :010 > customer = NetSuite::Records::Customer.get(:internal_id => 7996)
HTTPI GET request to webservices.netsuite.com (net_http)
HTTPI POST request to webservices.netsuite.com (net_http)

Solution

  • You can't pull a Transaction record – you have to pull a specific type or transaction record. Some types include: Invoice, SalesOrder, and CashSale.

    Try going to the following url:

    https://system.netsuite.com/app/accounting/transactions/transaction.nl?id=3820

    This should give you an idea of what transaction type the record is. If it's an Invoice, you would retrieve it using:

    NetSuite::Records::Invoice.get(1234)
    

    Here are some rough notes on the NS transaction flow. Some of it might be specific to our instance, but the majority of it applies to NS as a whole and might be helpful to you or others trying to piece together how NS works.

    • most of the time every CashSale (CS) and invoice, has a sales order (SO) associated with it. In the case of a recurring charge (like a monthly service fee) a CS or invoice does not have to have a SO associated with it
    • a SO can either have a sales paid order or an invoice associated with it. Ex: if someone paid on the spot with a CC, then it generates a "Cash Sale"
    • a SO, CS order, and invoice all have similar data but all have unique NS IDs. They aren't different views of the same data ala Contact vs Customer view on the same NS ID.
    • a SO will never progress past the "billed" state even after a full payment has been made
    • transactions are a flow. each record represents something semantically. therefore, in the normal flow of business, one might be generated as a consequense of another. so, a Sales Order means, a sales person was on the phone with a person and they ordered something if the company will pay for it later then when it gets "Billed" that generates an Invoice, which is a statement requesting payment for goods/services