Hello, I'm trying to add a button that will downlo...
# suitescript
r
Hello, I'm trying to add a button that will download a file from the file cabinet on a Suitelet. The Suitelet is written in SS2.0. To add the client script for the button's action to the form, I tried using both form.clientScriptFileId and form.clientScriptModulePath. However, I'm getting this error message: "type":"error.SuiteScriptError","name":"INVALID_API_VERSION_FOR_FORM","message":"You cannot use this API with this version of SuiteScript."
p
Is the header section correct at the top of the clientscript?
Copy code
* @NApiVersion 2.0
etc
r
It is and before I added that line it was creating the form fine and adding fields. It seems to just be having an issue with those particular methods
n
and presumably your "form" is the form Object?
r
@NElliott that's right.
n
Copy code
var form = serverWidget.createForm({
        title:'Invoice T&M Schedule Maintenance',
        hideNavBar:false});

      form.clientScriptModulePath = './Cat_tandm_cl.js';
like that^
b
The error is usually thrown when netsuite thinks the client script you are adding is using suitescript 1
Make sure the client script is valid suitescipt 2 (proper comment at top and valid module define)
Share the client script if you still have problems
m
I’ve seen this error before, and I seem to recall it being something really stupid that I did in the client script, like I forgot to return an object with my functions to expose them.
r
I think it's definitely a problem with my client script as @mattdahse mentioned. I have it returning the function but now SDF in Eclipse isn't letting me upload the script because it's missing an entry point. I'm looking at the docs for client scripts and there doesn't seem to be a good entry point that fits this case. Does it really need one? In SS1.0 you can just provide a function definition without creating a formal script record with entry points, iirc
Client script: define([],function(){ function downloadTemplate(){ window.location.href = "SampleFile.csv"; } return { downloadTemplate : downloadTemplate } });
m
@rmhollands You need to remove the @NApi tag that identifies this as a client script.
You don’t need a script record or deployment for the client script attached to the form of your suitelet.
If you identify your script as a client script, NetSuite will validate that you have entry points. You don’t need any if it’s just a click-handler.
r
Thanks everyone for your help. I'm getting some other error message now though: "This API is only supported in client entry point scripts and custom modules". Guess it's time for me to create a ticket with the consultants. I don't know why NetSuite makes it so hard to do something as simple as add a button to a form and have it perform an action and they didn't really bother to provide comprehensive documentation for SS2.0 for doing what should be a very common activity, but here we are
b
its not generally a hard task once you know which apis you are supposed to be using
you can try making a new script with these files in your SuiteScripts folder
s
@rmhollands just add a blank pageInit function to your exports, that way the script has a real client script entry point
👍 2