Hi guys. I am trying to attach custom code to an ...
# suitescript
w
Hi guys. I am trying to attach custom code to an address form. When I attach the SuiteScript 2.0 client script, it thinks that it is actually a SuiteScript 1.0 script. I have @NApiVersion 2.x at the top of the page. Is this a bug with Netsuite?
b
How are you attaching the code
w
I am going to 'custom code' on the form record and attaching the client script which is all in suitescript 2.0
b
that is a valid way to attach suitescript 2.0
what does your script file look like
n
do you have the '*@NApiVersion 2.x' header?
nvm, reread your original post...
w
I can give you the exact code, it is pretty simple: /** *@NApiVersion 2.x *@NScriptType ClientScript */ define([], function() { function validateAddress(){ alert('validate address'); } return { validateAddress, validateAddress } });
I have a custom action on that address form called validateAddress
b
your return looks funny
i don't think it is actually valid javascript
but beyond that, you don't implement any client script entry points
w
The only way I can get it to work is to remove everything and have only this: function validateAddress(){ alert('validate address'); nlapiSetFieldValue('attention', 'test attention' ); }
b
go implement a pageInit that does nothing
w
It does nothing. When trying to click the button, it can't find the function that I have the code for in the client script.
When trying to edit the suitescript 2.0 file it won't let me edit it because Netsuite is detecting it as a suitescript 1.0 file.
b
Copy code
return {
     validateAddress: validateAddress,
     pageInit: function() {}
};
implement a client script entry point in your client script. validateAddress is not a valid client script entry point
w
validateAddress is in my custom action for that form, and to use that action you need to define the function in the client script. When removing the SuiteScript 2.0 define and having only the validateAddress() function by itself in the script, and writing suitescript 1.0 code, it works. When removing the function altogether, the file is still detected as suitescript 1.0 and nothing works.
b
im saying that the code you shared is not a client script
you need to implement any one of client script entry points for netsuite to detect it as a valid suitescript 2 client script
adding the entry point will do absolulty nothing for your validateAddress action, it is only to help NetSuite validate your script
you will probably need to remove and then add back the script file to get it working again
w
No you don't need to implement every entry point for it to be considered a client script. We have plenty that don't. Thanks for your help. I ended up adding @param {dialog} dialog to the comments near the script type and script version declarations and it suddenly detected it as a 2.0 script.
n
Are you using it as a standard Client Script? Like validateField, fieldChanged? If yes, your function is invalid. If you are creating a custom function, like for adding a button in User Event... include a standard pageInit function.