-2

I want to use nlapi (Suite Script API) of Netsuite in chrome Extension

1 Answers1

1

In order to have a chrome extension have access to SuiteScript API you would need it to inject a script onto your NetSuite page that utilizes those APIs. Your Chrome extension manifest file should look something like this:

{
    "manifest_version": 2,
    "name": "NetSuite APIs",
    "description": "This extension will inject a script onto a NetSuite page that uses NetSuite's APIs",
    "version": "1.0.0",
    "content_scripts": [
        {
            "matches": [ "https://*.netsuite.com/*" ],
            "js": [ "sample.js"],
            "run_at": "document_end"
        }
    ]
    "permissions": [
        "tabs",
        "<all_urls>",
        "gcm"
    ]
}

This would inject the file sample.js into any page from the NetSuite domain once the page has fully loaded. Your sample.js file could look something like:

const recType = nlapiGetRecordType();
if (recType === 'salesorder') {
  const customer = nlapiGetFieldText('entity');
  alert('Let\'s make a big sale for ' + customer);
}

If you want to use SuiteScript 2.0 you will have to require in the modules, so your sample.js file would look like this:

require(['N/currentRecord'], function (currentRecord) {
    const rec = currentRecord.get();
    const recType = rec.type;
    if (recType === 'salesorder') {
      const customer = rec.getText({ fieldId: 'entity' });
      alert('Let\'s make a big sale for ' + customer);
    }
});
Jon Lamb
  • 1,413
  • 2
  • 16
  • 28