I'm trying to load a 3rd party software, but all t...
# suitescript
s
I'm trying to load a 3rd party software, but all they have are min.js. Is there a way to use that still in netsuite 2.1 files?
s
Likely can just load it directly onto the page in an inlinehtml field assuming they have unpkg link or something along those lines
s
trying to load xlsx and getting
cannot read property 'utils' of undefined
b
modern versions of xlsx js require you to use a require Configuration since the module uses
Copy code
if(typeof define==="function"&&define.amd)define("xlsx",function(){
s
Sadly it doesn't work even wrapping it in that and defining the define
b
what does your require configuration look like?
s
Copy code
if (typeof define !== 'function') {
    var define = require('amdefine')(module);
}

define(['xlsx', './xlsx.full.min.js'], function (xlsx, xlsxMinTwo) {
  var utils = xlsxMinTwo.utils
  return {utils}
})
the xlsx works. The xlsxMinTwo doesn't work
The xlsx.core.min.js also has this
Copy code
if (typeof exports !== 'undefined') make_xlsx_lib(exports);
else if (typeof module !== 'undefined' && module.exports) make_xlsx_lib(module.exports);
else if (typeof define === 'function' && define.amd)
    define('xlsx', function () {
        if (!XLSX.version) make_xlsx_lib(XLSX);
        return XLSX;
    });
b
i dont see your configuration, but xlsxMinTwo isnt using the require configuration and wont work
netsuite does not support named modules defined using
Copy code
define('xlsx', function () {
s
"paths": { "xlsx":"/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsx.js" "xlsxMin": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsxMin.js", },
b
which is why you need to use the supported way of named modules,
s
xlsx is in the config file
b
you would need to use xlsxMin instead of xlsx.full.min.js
s
i'VE TRIED THAT AS WELL
b
which file is xlsxMin.js?
s
also, this doesn't seem to be using the namdConfig file? It keeps saying that it cannot find the xlsxCore.js and xlsxFull.js
Copy code
if (typeof define !== 'function') {
    var define = require('amdefine')(module);
}

/**
 * @NApiVersion 2.1
 * @NModuleScope Public
 * @NAmdConfig  /SuiteScripts/AccentDecor/Libs/helperConfig.json
 */
define(['xlsxCore', './xlsxFull'], function (xlsxCore, xlsxFull) {
    return {
        xlsxCore: xlsxCore,
        xlsxFull : xlsxFull
    };
});
xlsxMin is the above code
{
"paths": {
"xlsx": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsx.js",
"xlsxMin": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsxMin.js",
"xlsxCore": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsx.core.min.js",
"xlsxFull": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsx.full.min.js",
}
}
b
Copy code
'./xlsxFull'
is essentially doomed, not the id defeined in your paths
s
sorry, ignore that. I was undoing code to send it here and forgot to remove that one
they both say 'xlsxCore' and 'xlsxFull'
b
Copy code
xlsxCore
looks reasonable, though i dont think the xlsx core file actually works
i would recommend only one path to xlsx
s
Yeah, that's why I'm trying both of them.
b
all of these files are probably trying to use the xlsx id
s
it's not using the NAmdConfig for some reason
b
id want to see your actual json file
the code you shared is not actual json
s
helperConfig.json
b
Copy code
{
  "paths": {
    "emailHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/emailHelper.js",
    "cHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/commonHelper.js",
    "commonHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/commonHelper.js",
    "dataHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/dataHelper.js",
    "encodeHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/encodeHelper.js",
    "errorHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/errorHelper.js",
    "searchHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/searchHelper.js",
    "sublistHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/sublistHelper.js",
    "mapReduceHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/mapReduceHelper.js",
    "merchantEHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/merchantEHelper.js",
    "xmlHelper": "/SuiteScripts/AccentDecor/Libs/HelperClasses/xmlHelper.js",
    "smartySheets": "/SuiteScripts/AccentDecor/Libs/Config/smartyStreetsConfig.js",
    "fileConfig": "/SuiteScripts/AccentDecor/Libs/Config/fileConfig.js",
    "allocationStrategy": "/SuiteScripts/AccentDecor/Libs/Config/allocationStrategy.js",
    "integrationStatus": "/SuiteScripts/AccentDecor/Libs/Config/integrationStatus.js",
    "ramda": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/ramda/dist/ramda.js",
    "lodash": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/lodash/dist/lodash.js",
    "moment": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/moment/moment.js",
    "xlsx": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsx.full.min.js",
    "jsonxml": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/JSONXML/jsonxml.js",
    "settings": "/SuiteScripts/AccentDecor/Tools/Global Preferences/ad_settings.js"
  },
  "map": {
    "*": {
      "dmHelper": "dataHelper",
      "intStatus": "integrationStatus"
    }
  }
}
define one xlsx
s
Ok, so to backup, the only reason I'm even trying the min files is I was talking with someone on github at xlsx and they wanted me to try the full min files. The initial error I'm having is it is doing thigns like converting ’ to ’ when doing toString() or out.join(""). So it feels more like a netsuite javascript environment than xlsx
Also, I get the error when importing the xlsxMin file Cannot read property 'utils' of undefined
b
Copy code
Cannot read property 'utils' of undefined
usually means xlsx is undefined
which is usually fixed through a require config
s
i got it to where it gives sheet_to_txt is not defined meaning xlsx.utils isn't defined
Copy code
if (typeof define !== 'function') {
    var define = require('amdefine')(module);
}

/**
 * @NAmdConfig /SuiteScripts/AccentDecor/Libs/helperConfig.json
 */
define(['xlsxFull'], function (xlsxFull) {
    return {
        xlsxFull
    };
});
that's what is xlsxMin.js
b
and im telling you to stop using multiple ids for xlsx
use xlsx as the path
s
there's only 1 path in there. What are you talking about?
b
do not use xlsxFull or any of the other variations you are trying
s
changed it to xlsx with no change unfortunately
b
what does your config file look like now?
s
xlsxMin is where the require is happening
Copy code
"xlsxMin": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsxMin.js",
"xlsx": "/SuiteScripts/AccentDecor/Libs/ExternalLibs/xlsx/xlsx.full.min.js",
There we go. I changed it to return xlsx instead of return {xlsx:xlsx}
b
for your output issues, you may want to try using the more general write method so that you can output in xlsx format with the type set to base 64 so that you can actually create files in the file cabinet
s
they have to be text or csv files and can't be xlsx files. It's for a 3rd party system we have to FTP data to
b
you may want to actually use a csv specific library
s
Funny thing is, I just tried it and everytime it gets converted to csv, it causes the issue
I think that it's a netsuite issue. if i return the single result, it returns a ’. If I return the full json, it returns ’
b
i wouldnt use sheet js output unless you really need xlsx
output options are very dependent on environment
s
I didn't. I used something I wrote a long time to convert things into csv
also JSON.stringify() does the same thing
Something is happening when converting it to a string
b
im assuming you are reading an excel file somewhere
so you want to make sure that input is correct
s
Nah. I'm pulling it up in notepad++
and a tool called beyond compare
b
huh
s
but yeah, wanting to make sure that it is read correctly wherever it goes
b
you want to use sheet js to read or write excel files
you say you want csv output, which means you should hopefully be using its excel reading capabilities
s
I started using xlsx because it was an already written way to cdreate a tab delimited text file
b
if you arent reading or writing excel, then papaparse is a csv specific tool
s
I don't know how the 3rd party system is reading it. I'm still waiting to hear from them to see if their system will parse that correctly
ok, i'll check it out. I still think that upon further inspection, there is an issue with the javascript version netsuite is using. Because even if I just convert the json to a string, I see the same issue
b
not sure how you are generating your object
it sounds like its from search results, which means you probably want to figure out which combination of search results is causing your issue
if possible, figure out how to generate a hard coded version of it
s
Like I said, if I return results[256] it works. If I return results, the issue is there
b
and results 250-260?
s
those don't have the special characters
meaning there is nothing to be wrong
b
if you dont think a single search result causes the problem, then its a combination
s
when I return results[256] all of the results have been returned and combined at that point.
b
with it being unlikely that all your search results is the minimum necessary
s
it is when converting the json results to a string that the issue is happening. And only when lines 0 and 1 are present