Let me step back and say my goal, and maybe I can ...
# suitescript
e
Let me step back and say my goal, and maybe I can understand how to better achieve it.... I'm building a suitelet that is used in our warehouse for picking/packing orders. (We currently use the SS1.0 version I built without issues, but I'm itching to get it to 2.0) In 1.0 I just created a JS file with a bunch of functions that were used across many pages of the suitelet and loaded it on each page. In 2.0 I cant figure out how to add a single script file to each page and allow the functions to be called from the browser
e
Put the functions you want to call within a custom module, then have your client script import the custom module
e
Would this allow me to write html like <input onchange=coolFunction()> and allow coolFunction to execute if I changed what was in the input field?
(assuming coolFunction was part of the custom module)
j
A SS 2.0 custom module imported into the clientscript of the Suitelet would only be accessible in the conext of the client script unless you take some other action. It sounds like you want the custom module accessible globally on the window object in the browser. Is the Suitelet just rendering HTML apposed to .createForm and subsequent addField calls to create the input elements
s
Yeah in general/basic use, you attach the client script to the suitelet to have access to the standard entry points you get from client scripts. You certainly could have more functions, like for button clicking as well as an example..
e
So in the SS1.0 version, I used createForm and added just 1 single HTML field (my "mainDiv"). Then I used a client script to add/arrange/style everything else. i.e. Would create fields client side using document.createElement... then append them to the mainDiv. But I would add event listeners to those created fields as well, and they would call functions that existed in a linked script (that was accessible globally)
s
I guess my main question is why are you creating suitelets this way, this is not how the NS API's are designed to work at all. If don't want your page to look like native NS, then at least use some sorta framework as opposed to writing raw html sitting in an inline html field (maybe you are doing this, not sure). It's so hard to sustain long term and whoever comes along next is going to be lost as to why things are made this way.
e
I guess my short, inexcusable explanation would be: It aligned with my companies needs, and my skill set at the time of building it. Your constructive criticism is fair and warranted. I'm ripping on the emergency brake and am going to delve into a better structure to achieve a more sustainable and scalable path forward. I appreciate your question- and I think it will help me moving forward
s
The serverWidget module is really easy/straightforward to get started with as long as your pages need fairly simple design/interaction.