GithubHelp home page GithubHelp logo

zmhan-github / typings-suitescript-2.0 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from headintheclouddev/typings-suitescript-2.0

0.0 1.0 0.0 1.39 MB

TypeScript typings for SuiteScript version 2.0

License: MIT License

JavaScript 97.05% TypeScript 2.95%

typings-suitescript-2.0's Introduction

SuiteScript 2.0 Typings

Build Status devDependencies Status Join the chat at https://gitter.im/typings-suitescript-2-0/Lobby

Installation Instructions

npm install --save-dev @hitc/netsuite-types

Usage

Once installed, you need to configure TypeScript to find the library declarations and import the libraries as needed into your scripts.

TSC (TypeScript Compiler) Configuration

You can import the modules and use them like normal using standard TypeScript syntax. Just make sure your compiler is configured to use the amd module format and the es5 target. Create a file called tsconfig.json in your project root and have these options configured:

{
  "compilerOptions": {
    "module": "amd",
    "target": "es5",
    "moduleResolution":"node",
    "sourceMap": false,
    "newLine": "LF",
    "experimentalDecorators": true,
    "noImplicitUseStrict": true,
    "baseUrl": ".",
    "lib": ["es5", "es2015.promise", "dom"],
    "paths": {
      "N": ["node_modules/@hitc/netsuite-types/N"],
      "N/*": ["node_modules/@hitc/netsuite-types/N/*"]
    }
  },
  "exclude": ["node_modules"]
}

The key components are baseUrl and paths.

Then simply import your modules and go.

Writing SuiteScript

At the top of every script you will want to have the following lines added:

/**
 * @NAPIVersion 2.0
 * @NScriptType ClientScript
 */

import {EntryPoints} from 'N/types';

N/types and EntryPoints isn't actually in the NetSuite API, but it is something that is included with this library to give you type definitons for your entry point functions. For example:

import {EntryPoints} from 'N/types';
export let pageInit: EntryPoints.Client.pageInit = (context: EntryPoints.Client.pageInitContext) => {
  //Your IDE will now autocomplete from the context argument. For instance use this to access context.mode and context.currentRecord in this pageInit example
}

Notice that we are exporting the function pageInit that will need to be referenced in the NetSuite Client Script record as an entry point.

Then if you're using a TypeScript-aware text editor you'll get syntax highlighting, error detection, embedded apidocs, type-cheking, and autocomplete for all of the SuiteScript 2.0 modules and types. For instance the free VSCode from Microsoft will work out of the box.

User Event Example

Full example for a User Event Script might look something like this:

/**
 * @NAPIVersion 2.0
 * @NScriptType UserEventScript
 */

import {EntryPoints} from 'N/types';
import * as log from 'N/log';

export let beforeSubmit: EntryPoints.UserEvent.beforeSubmit = (context: EntryPoints.UserEvent.beforeSubmitContext) => {
    let x = context.newRecord.getValue({fieldId: 'companyname'});
    log.audit('value', `companyname is: ${x}`);
};

Suitelet Example

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */

import {EntryPoints} from 'N/types';
import * as record from 'N/record';

export let onRequest: EntryPoints.Suitelet.onRequest = (context: EntryPoints.Suitelet.onRequestContext) => {
    let folder = record.load({type: 'folder', id: 36464});
    let allfields = folder.getFields().join(', ');
    context.response.write(`<br>all fields: ${allfields}`);
};

This example exports the function onRequest that needs to be referenced in the script record.

Updates

You can download the latest published typings library at any time by simply running the command:

npm install --save-dev @hitc/netsuite-types

typings-suitescript-2.0's People

Contributors

mrrob avatar johnogle222 avatar darrenhillconsulting avatar shawntalbert avatar cancerberosgx avatar victor-njimezi avatar nvldk avatar extend-apps avatar kylejoneswinsted avatar jerry-atom avatar jeffreymkabot avatar dependabot[bot] avatar jonnyboy333 avatar tomaswatz avatar hurrutia-rsm avatar mayerlench avatar yuhuix avatar umakanthgarimella avatar christopherwxyz avatar accountingnerd avatar aviacollvinent-netsuite avatar gitter-badger avatar slogsdon avatar jonesdev avatar olegbespalov avatar nic-wolf avatar ludeknovy avatar kenofthenorth avatar jhult avatar jcormont 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.