Rick Goodrow
02/26/2025, 5:56 PMfoo()
being defined outside of a define()
statement as part of client scripts loaded in EDIT mode so that it can be called via a button created with form.addButtion()
defined via a User Event script. Within that function foo()
, I'm using require()
to load necessary modules to do what the function needs to do on the client side.
The issue is how to deal with custom modules. All of the custom modules I'm using use a path reference that is defined in an namdconfig.json
, so for a define statement, it'd be define(['N/https', 'ME/mine'], (https,mine) => {...})
, however when trying to do the same with require require(['N/https', 'ME/mine
], (https,mine) => {...}` , the mine
module isn't loaded.
Doing some research, if I configure the require function directly before use the following inside of foo()
let runRequire = require.config(<contents of namdconfig.json>);
runRequire(['N/https', 'ME/mine'], (https/mine) => {...});
then the mine
module is available for use.
The issue with that is having to copy the contents of namdconfig.json
into each function that needs it. I'd prefer to just point to the file, but require.config()
needs an object. So is there any reasonable way to use require()
in a client script with custom modules in a sane way?erictgrubaugh
02/26/2025, 6:00 PMfoo()
is defined outside the Client Script's define()
? I'd expect it to be defined within the define()
and included in the Client Script's return
statement so that it would be accessible to the button.
Then as long as the Client Script has @NAmdConfig
defined, I'd expect the custom module to be found. I haven't tried this specifically with the inline require()
call though.Rick Goodrow
02/26/2025, 6:06 PMcs_sales_orders.js
client script attached to all sales orders. cs_quote.js
client script attached to quotes. Both of those scripts use a variation of define([...,'ME/common'], (..., meCommon) => { ... }
to get the common client functions that will run for both transactions. pageInit(), fieldChanged()
, etc.. all run on the cs_*.js
files, and then call meCommon.otherFunc()
when using something in common.
I tried defining the foo()
function (and exporting) the button calls within the ME/common
module, but when the button is clicked, says function is not defined. My guess is that because it's defined within ME/common
and not on the original deployed client script, it's not visible.Rick Goodrow
02/26/2025, 6:07 PMalien4u
02/26/2025, 6:13 PMmeCommon
structured? are you sure you are exporting/returning foo()
?Anthony OConnor
02/26/2025, 6:18 PMI have a functiona function called by a button click on form that was created in a before load UE doesn't NEED to be outside of the definebeing defined outside of afoo()
statement as part of client scripts loaded in EDIT mode so that it can be called via a button created withdefine()
defined via a User Event script.form.addButtion()
Anthony OConnor
02/26/2025, 6:21 PMAnthony OConnor
02/26/2025, 6:24 PMAnthony OConnor
02/26/2025, 6:26 PMfunction buttonClicked({params}){
meCommon.actualFunction({params});
}
Anthony OConnor
02/26/2025, 6:27 PMfoo()
?Rick Goodrow
02/28/2025, 4:06 PMdefine()
, and am no longer using require()
or defining any functions outside of a define()
statement. @battkI have put my own Jira a revisit to look at consolidating within a single .clientScriptModulePath
file in the future.