RE: How to resolve jQuery issue with 2019.2 SuiteScript 2.0 portlet script?
In 2019.2 there have been some changes on NetSuite’s side that are causing some jQuery libraries to not work correctly for SuiteScript 2.0 scripts. jQuery v. 2.1.3 and jQuery-UI v. 1.11.4 are being utilized. The issue is primarily with DataTables, as it will return an error of ‘$(…).DataTable is not a function’, however this was never an issue in 2019.1
I’m hoping that someone else has also encountered this issue, and may have come up with a solution?
Example of how the libraries are being added to the script (with exception of jQuery and jQuery-UI):
“paths”: {
“jquery”: “./Libs/jquery-2.1.3.min.js”,
“jqueryui”: “./Libs/jquery-ui.min.js”
}
}
I’ve had this issue in the past, in my experience it is more having to do with the jQuery library not having been loaded previously to the other library which holds jQuery as a dependency. If you are injecting libraries via html as you have shown, you could try explicitly loading your version of jQuery first.
Or (I think more best practice) uploading the jQuery and other library scripts into NetSuite file cabinet and referencing via config.json and @NAmdConfig
script tag. For this option, I have needed to have jQuery in config.json file using the shim section and listing it in deps for other scripts. See https://requirejs.org/docs/api.html#config-shim for reference.
Thanks, I tried referencing jquery and jquery UI in a config.json file with the @NAmdConfig tag linked to it but it will come up with the error “Cannot call method \”createElement\” of undefined” after doing so.
can you share your config file and how you are referencing it
Sure, I updated the question to add the additional details of how jQuery is being referenced.
what about the DataTable lib itself, how is that being introduced? I would recommend doing all three via either config or inlinehtml whichever you decide