By design client side scripts may be used in form in "edit" mode only. In case an action needs to be performed when viewing the record (e.g. by clicking a button) then the following setup and code will work.
In the following example simple alert()
will represent client-side script.
clientFunction.js
" with the following function:function
clientFunction(
)
{
alert(
'Client script triggered'
)
;
// other client-side code
}
This client-side script has to be uploaded into NetSuite account using following steps:
- Customization > Scripting > Scripts > New: Client script
- Name = Client Function
ID = _client_function
Script File = select "- New -" and upload the "clientFunction.js
" file
Save (no deployment is needed)
beforeLoad
function which adds a button and assign newly created script to run upon clicking:function
beforeLoadScript(
type,
form,
request)
{
form.setScript
(
'customscript_client_function'
)
;
form.addButton
(
'custpage_recalc'
,
'Button (Client)'
,
'clientFunction()'
)
;
}
This script should be uploaded into NetSuite and deployed on record where the button should be added and client-side script executed.
Expected result is a new button on a form in view mode, alert with "Client script triggered" message is shown by clicking it.
Also, for client scripts that needs to have parameter passed to it, use the example code below as reference.
Client Script:
function
clientFunction(message
)
{
alert(
message
)
;
// other client-side code
}
User Event Script:
function
beforeLoadScript(
type,
form,
request)
{
var message = 'Client script triggered'; form.setScript
(
'customscript_client_function'
)
;
form.addButton
(
'custpage_recalc'
,
'Button (Client)'
,
'clientFunction("'+ message +'")'
)
;
}
DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code
No comments:
Post a Comment