xpeldev
xpeldev

Reputation: 2080

Referencing custom AMD Modules in SuiteScript 2.0

Netsuite says to include the module id when creating custom modules like so:

define(module_id, [dependencies], function)

However when I do the module is not found:

TypeError: Cannot read property "XPELPCenterModule" from undefined (/path/to/mysuitelet.js#35)

When I remove the ID, it works???

Hello Human Coder

What am I missing. Im am calling both of them the same way

function (ui, email, runtime, search, record, log, render, cache, crypto, file, pcenter) {
        var p = new pcenter.XPELPCenterModule();

.....

p.helloWorld('Human Coder');

here are the module code examples:

WORKING CODE:

define(["require", "exports"],
function (require, exports) {

    var XPELPCenterModule = /** @class */ (function () {

        function XPELPCenterModule(name) {
            this.name = name;
        }

        XPELPCenterModule.prototype.helloWorld = function (name) {
            return 'Hello ' + name;
        };

        return XPELPCenterModule;
    }());

    exports.XPELPCenterModule = XPELPCenterModule;
});

NON WORKING CODE:

define('XPELPCenterModule', ["require", "exports"],
function (require, exports) {

    var XPELPCenterModule = /** @class */ (function () {

        function XPELPCenterModule(name) {
            this.name = name;
        }

        XPELPCenterModule.prototype.helloWorld = function (name) {
            return 'Hello ' + name;
        };

        return XPELPCenterModule;
    }());

    exports.XPELPCenterModule = XPELPCenterModule;
});

Upvotes: 3

Views: 1358

Answers (1)

xpeldev
xpeldev

Reputation: 2080

The trick was to use @NAmdConfig and add a .json config file of your module paths:

/**
 *@NApiVersion 2.0
 *@NScriptType Suitelet
 *@NModuleScope Public
 *@NAmdConfig  /path/to/myModule.json
 */

.JSON CONFIG FILE:

{
  "paths": {
    "XPELPCenterModule": "/path/to/myModule"
  }
}

Upvotes: 8

Related Questions