Giter VIP home page Giter VIP logo

netsuite-fasttrack-toolkit's Introduction

Netsuite Fast Track Toolkit

Join the chat at https://gitter.im/ExploreConsulting/netsuite-fasttrack-toolkit A bundle of joy for NetSuite SuiteScript developers.

See the overview document for an intro and sample code.

A few features:

  • single file deploy - you only add a single file to the suitescript libraries tab.
  • bundles popular open source tools such as lodash and momentjs
  • create/read/update NetSuite records using plain javascript objects
  • work with NetSuite search results as plain javascript collections which enables use of powerful libraries such as lodash and LazyJS.

Getting Started

Add the library to your project

npm install netsuite-fasttrack-toolkit

To execute the unit tests

npm test

If using TypeScript, add the following line to the top of your SuiteScript file

///<reference path="node_modules/netsuite-fasttrack-toolkit/index.d.ts"/>

Create a customer record

    var customer = nsdal.createObject('customer', ['firstname', 'lastname', 'companyname'])

    customer.firstname = 'joe'
    customer.lastname = 'smith'
    customer.companyname = 'my company'

    var recordid = customer.save()

Sales Order Lines (sublist support)

   var salesOrder = nsdal.loadObject('salesorder', '1234', ['entity', 'department','createddate'])
                          .withSublist('item', ['item', 'quantity','amount'])

    // do something with body fields 
    salesOrder.department
    salesOrder.entity
    salesOrder.createddate // this is a momentjs instance

   // find all line items with quantity > 100
   var highQtyLineItems = _.filter(salesOrder.item, function(line){ return line.quantity > 100 })

   // process each line item
   _.each(salesOrder.item, function(line) {
   /* do something with 'line'*/
     line.item
     line.quantity
     line.amount
   })

   // add a line item
   var newline = salesOrder.item.addLine()
   newline.item = '123'
   newline.quantity = 1
   newline.amount = 23.0

Lazy search and iterate over results

    // create search, returning 3 customer fields
    var search = lazy.createSearch(['customer'],[['firstname', 'contains', 'joe']],
     ['internalid','firstname', 'phone'] )
     .nsSearchResult2obj() // convert search results to plain javascript
    .take(10000) // process only the first 10000
    .map(function(customer) {
        // log the phone number field of each customer
        log.debug('customer phone', customer.phone)
    }).toArray()

TypeScript (optional)

The library is written in Javascript but you can use it with TypeScript 2.x.

Examples using TypeScript:

Load a customer record (TS)

   ///<reference path="node_modules/netsuite-fasttrack-toolkit/index.d.ts"/>

  interface Customer {
        companyname:string
        phone:string
    }

    var customer = nsdal.loadObject<Customer>('customer', '1234', ['companyname', 'phone'])

    // customer is of type Customer and NSDALObject, so it has properties and traditional nlobjRecord methods
    customer.phone = '123-456-7890'
    customer.getFieldText('companyname')

   // nlapi calls are type checked
   nlapiRequestURL('url')

Contents

  • TypeScript Documentation is in the *.d.ts files. Just add

      ///<reference path="node_modules/netsuite-fasttrack-toolkit/index.d.ts"/>
    

    to your script.

  • EC_SharedLibrary_Common.js - common code for use on either server-side or client-side scripts.

  • EC_Search.js - Provides a search api that uses constant memory and lazy evaluation. Also includes a simplified definition for search filters/columns.

  • EC_nsdal.js - Active Record style Data Access Library for netsuite records.

Utility Libraries

These best-of-breed open source libs are brought in by npm and are included in the build:

  • lodash - functional utility belt
  • moment - awesome datetime library
  • lazyjs - a lazy version of underscore/lodash. Newer than lodash and initially only used for the lazy search lib.
  • aop - aspect oriented programming lib for javascript

These are brought in by npm but only used in dev (not in the built binary)

  • sinon - mocking framework for tests/specs
  • typescript - for ES6/7 and strong typing (optional)
  • karma - browser based test runner
  • mocha - universal test runner and framework
  • chai - assertion library for tests
  • gulp things - for building

Other

  • nlapi.js - the netsuite api javascript documentation direct from netsuite. This provides code completion and docs for methods inside WebStorm.
  • nlapi.d.ts - same as above (but stronger typed) definitions for TypeScript

Building a release

To create a single file library for referencing in NetSuite

  1. Tag the repository with a semver version number (e.g. 1.2.3)
  2. Edit 'package.json' and update the version variable to match the tag () you're working with
  3. Run gulp from commandline or in WebStorm (menu View->Tool Windows->Gulp)
  4. Compiled output will be placed in dist/NFT-<tagversion>.js

Building the logging component requires webpack:

webpack Logging.js  --output-library LogManager --output-filename Aurelia-Logger-webpack-lib.js --output-library-target var

The gulp build does this automatically in code, but the equivalent commandline is above.

Tests

  • put tests under the tests folder
  • new tests should be in mocha/chai, run with karma (see tests/karma.conf.js)

Note: designed for SuiteScript 1.x. For the SuiteScript 2.x library, look here

netsuite-fasttrack-toolkit's People

Contributors

shawntalbert avatar gitter-badger avatar scurryone avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.