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):

var fldObj = portlet.addField({id: js_id, type: ‘inlinehtml’, label: null});
fldObj.defaultValue = ‘<script type=”text/javascript” src=”sourceHere”></script>’;
I am now adding jQuery and jQuery UI through a file, Portlet,json:
{
“paths”: {
“jquery”: “./Libs/jquery-2.1.3.min.js”,
“jqueryui”: “./Libs/jquery-ui.min.js”
}
}
Referenced in the script like so:
/**
*
*
* @NApiVersion 2.x
* @NScriptType Portlet
* @NModuleScope public
* @NAmdConfig ./Libs/Portlet.json
*
*/
define([‘N/runtime’,’N/xml’,’N/url’, ‘N/search’, ‘jquery’, ‘jqueryui’],
function(r, x, u, s, jquery, jqueryui) {}
Rookie Asked on September 12, 2019 in SuiteScript.
Add Comment
1 Answer(s)
Best answer

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.

Intermediate Answered on September 12, 2019.

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.

on September 12, 2019.

can you share your config file and how you are referencing it

on September 12, 2019.

Sure, I updated the question to add the additional details of how jQuery is being referenced.

on September 12, 2019.

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

on September 12, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor