Beau
01/07/2022, 6:11 PM_.permutations()
function.
Here is my Suitelet. lodash normally works, but the Suitelet errors out (Module does not exist: /lodash.js
) as soon as I add "permutations" to the define statement:
/**
*@NApiVersion 2.1
*@NScriptType Suitelet
*@NAmdConfig /SuiteScripts/modules.json
*@NModuleScope SameAccount
*/
define(["N/record", "N/search", "/SuiteScripts/lodash", "permutations"], function(record, search, _, permutations) {
return _.permutations(["apple","oranges","pears"], 2)
// supposed to return:
// [["apple","oranges"],["apple","pears"],["oranges","apple"],["oranges","pears"],["pears","apple"],["pears","oranges"]]
})
and here is my /SuiteScripts/modules.json:
{
"packages": [],
"paths": {
"permutations": "/SuiteScripts/lodash.permutations.js"
}
}
Below is a screenshot of how to get lodash.permutations.js working in other environments. It's usually easy to set up lodash's permutations in node or clientside browser, but I can't seem to figure out how to get it working in serverside Netsuite SuiteScript 2.X 🤔. Even copying and pasting this tiny permutations library within the Suitelet's define statement doesn't seem to get it append itself to lodash, so I'm sure I'm misunderstanding CommonJS vs AMD here...also tried to play around with require.config() instead of via NAmdConfig/modules.json, but couldn't get that working either.
Maybe I need to delete my lodash.js in Netsuite and load an AMD-version of lodash, and NAmdConfig-ify all my Suitelets for this AMD lodash? Is that the only way to get this tiny permutations library working?battk
01/07/2022, 9:34 PM"function"==typeof define&&define.amd?define(["lodash"],t)
battk
01/07/2022, 9:35 PMBeau
01/07/2022, 9:52 PMdefine(["N/record", "N/search", *"/SuiteScripts/lodash"*], function (record, search, _ ...
to define(["N/record", "N/search", "*lodash*"], function (record, search, _ ...)
? I don't think I need to even try to load a "permutations" on the Suitlet's define statement, I just need the configuration modules.json to refer to both lodash.amd.js and lodash.permutations.js? going to try to tinker with this more tonightbattk
01/07/2022, 10:00 PMbattk
01/07/2022, 10:01 PMbattk
01/07/2022, 10:01 PMbattk
01/07/2022, 10:01 PMBeau
01/07/2022, 11:38 PM"function"==typeof define&&define.amd?define(["lodash"],t)
....seems like "define.amd" evaluates to {"JQuery": true}? I didn't even realize the the Rhino or GraalVM engine is using JQuery?
Either way I'm able to get lodash permutations to work on the server side without creating a require Configuration if I just replace "define.amd" to "false" and let the this permutations library find lodash via "this._". A bit hack-y but seems like a lot of things are in Netsuite anyways 😅battk
01/07/2022, 11:54 PM