Custom Code Tab and Actions Tab in XML Definitions
In NetSuite, the Custom Code tab and Actions tab are used together to define custom buttons for custom forms. Custom buttons are a way for your users to intentionally execute client SuiteScript on custom forms. The buttons can be useful for executing a specific function when the user clicks the button on the form, such as creating a customized invoice.
You can add custom buttons to custom forms in SuiteCloud Development Framework (SDF) by specifying the actionBar
element to define the Action tab. For information about defining actionBar
in SDF custom objects, see Custom Buttons on the Actions Tab in XML Definitions.
Each custom button runs SuiteScript from the Custom Code tab, which you can define in SDF by specifying the customCode
element. For information about defining customCode
in SDF custom objects, see Custom Code Tab in XML Definitions.
The following SDF custom objects support the customCode
and actionBar
elements: addressForm
, entryForm
, and transactionForm
. For information about defining those SDF custom objects, see the following topics:
Custom Code Tab in XML Definitions
You can define the custom code tab by specifying the customCode
element, which contains the scriptFile
field that references a client SuiteScript 2.x file. The SuiteScript file can be located in the SuiteCloud Project or the File Cabinet for the target NetSuite account. Only client script files are supported for the Custom Code tab on custom forms. After deployment, the SuitesScript file is executed when the user clicks a custom button in the NetSuite UI.
Although you can define the Custom Code tab without defining a custom button, the custom button is required for the user to execute the code as an action.
For information about writing valid SuiteScript for custom buttons, see SuiteScript 2.x Client Script Type and SuiteScript 2.x User Event Script Type. Additional information is available in Associating Custom Code (Client SuiteScript) Files With Custom Forms.
Only SuiteScript 2.x scripts are supported for the scriptFile
value in customCode
. If you import a custom form into your SuiteCloud project and that form contains a scriptFile
reference to a SuiteScript 1.0 file, the XML for the script file does not appear in the form’s XML definition. For information about SuiteScript versions, see SuiteScript Versioning Guidelines.
When functions are specified in the SuiteScript file, they automatically appear enabled in NetSuite UI after deployment to the target account. The functions are read-only fields and cannot be modified in the XML definition for the custom form. The following client script functions are possible:
-
Page Init Function — pageinitfunction
-
Save Record Function — saverecordfunction
-
Validate Field Function — validatefieldfunction
-
Field Changed Function — fieldchangedfunction
-
Post Sourcing Function — postsourcingfunction
-
Line Init Function — lineinitfunction
-
Validate Line Function — validatelinefunction
-
Validate Insert Function — validateinsertfunction
-
Validate Delete Function — validatedeletefunction
-
Recalc Function — recalcfunction
The following example defines the Custom Code tab by specifying the customCode
element, which contains the scriptFile
field that references the client SuiteScript file invoice.js. The invoice.js file can contain functions used by custom buttons.
<customCode>
<scriptFile>[/SuiteScript/invoice.js]</scriptFile>
</customCode>
The customCode
element can be added to the following forms: addressForm
, entryForm
, and transactionForm
Custom Buttons on the Actions Tab in XML Definitions
You can add custom buttons to a custom form by defining the Actions tab using the actionBar
element. Each custom button is defined by a customButton
element, by specifying both a label and function. The label
field is the name of the button in the NetSuite UI, and the function
field is the function the button calls from the client SuiteScript file that is specified in the scriptFile
field on the same custom form.
For custom buttons to run the specified function, the function must exist in the client SuiteScript file that is defined on the Custom Code subtab on the same form. For information about defining the Custom Code subtab, see Custom Code Tab in XML Definitions.
Consider the following when working with custom buttons:
-
For the Custom Actions subtab to appear on the Custom Form tab after deployment, the Client SuiteScript feature must be enabled in the target account.
-
If you import a custom form into your SuiteCloud project and that form contains a custom button without a
scriptFile
reference, the buttons are still defined in the form’s XML definition. However, for the buttons to function on the form, thescriptFile
reference must be added to the form’s XML definition. For information about defining custom buttons on custom forms using the NetSuite UI, see Working with Custom Buttons.
The following example defines two custom buttons. The first button has the label Invoice Client, and runs the function invoiceClient
. The second button has the label Generate Report, and runs the function generateReport
. To execute, both functions must be defined in the client SuiteScript file referenced by the scriptFile
field for the customCode
element in the same custom form object.
<actionBar>
<customButtons>
<customButton>
<label>Invoice Client</label>
<function>invoiceClient</function>
</customButton>
<customButton>
<label>Generate Report</label>
<function>generateReport</function>
</customButton>
</customButtons>
</actionBar>
The actionBar
element can be added to the following forms: addressForm
, entryForm
, and transactionForm