hey everyone, I have a questions a client script i...
# suitescript
m
hey everyone, I have a questions a client script in a Suitelet when I use a CS in a Suitelet, I'd do something like this:
myForm = serverWidget.createForm({
title: 'my form',
hideNavBar: true
});
myForm.clientScriptModulePath = 'SuiteScripts/PathToScript/myclientscript_cs.js';
But this time, I am not using the serverWidget.createForm() -- instead, I am loading an HTML template, rendering it with N/render and writing that. I tried to add a client script in the dependencies that I set, but that doesn't work because it's not seen as a SuiteScript. I can't put the code right into a custom JS file, because it is trying to make use of the Google Maps API, and maps won't load that way. Any help is appreciated! Thank you!
a
Normally in your Suitelet you create a form, then you will use a HTML field to store the content of that rendered HTML. Unless you are doing something differently> The approach I normally use is: • Field to holds html (custom). • Field to hold client side script logic. Render the form and you normally do...
m
@alien4u right, that is how I normally do it as well, but I need to create it like it is shown here in the Embedding HTML from a Linked HTML Page in a Suitelet example, where I am not using
serverWidget.createForm
Is there any way to get a client script into the Suitelet in that example, I think is another way I could ask this
a
Untitled.js
I see, you are calling a link or showing HTML from a link / URL. Well the example they show there is very simplistic, nothing should stop you from: • Create a form. • Do their getFunction(context) logic example. • Store the returned HTML into an inline HTML field. • Then render the Suitelet as you normally do...
m
ok, thank you. I actually tried
addCustomDataSource
last night, but couldn't get it to work. The error said it wasn't the correct datasource Object, but I see some differences in how I did it and your example. I hadn't worked with
addCustomDataSource
before last night. Thanks again!
a
Bottom line is, you don't need to do what they are doing on their getFunction() example: • context.response.write(contentDocument); You should be able to write o render that HTML in a different way without having to give up all the Suitelet functionality.
m
ok, thanks, the header and form contents and other page requirements are quite involved, and it would just be sooo much better to link/load the template, but the client script has to be there. I am going to give this a try in a bit!
e
You should be able to use a
<script>
tag to load your Client Script into the page, but none of its entry points are going to fire since you're not using native UI components, and you may need to make the file available without login.
m
@erictgrubaugh I tried that, because I just need a JS file, and everything worked except loading the Google Maps API. I can take the exact same code out and load via script tag on a simple index.html and the Google Maps API works, so, it would seem to be where their API won't work in a Suitelet. I looked into some of the Maps API settings, so see if I could allow it, but didn't come up with anything.
I read somewhere that Maps, Recaptcha, etc, will only work in a Suitelet if it's handled in a client script, but I feel like a couple years ago i had Recaptcha working in a Suitelet with just a customJS file in a script tag, but I just can't remember -- been too long. 😬
@alien4u wouldn't the problem with this approach be that the form fields needed exist in the template. So loading the template as INLINE HTML to a form.create, the form fields won't be in the POST ??
a
You beed to override the regular submit action added by the NetSuite form and build your own submit (post) handler.
m
If the Maps API would just load in a normal <script> JS file, I'd have been done with this yesterday. I can't get google MAPS to load like I would on a "normal" website. I read that it needs to be in a ClientScript. But getting the Client Script into one built on a loaded/linked template isn't working out so well. 🤔