In NetSuite, you can manipulate the position of fields within a form using the `Form.insertField(options)` method. This method allows you to insert a field in front of another field, providing flexibility in organizing the layout of your forms. Here’s a detailed explanation of how to use this method, along with a practical example.
Method Description
The `Form.insertField(options)` method is used to insert a field in front of another specified field within a form. This method is supported in SuiteScript 2.x Suitelet Script Type and SuiteScript 2.x User Event Script Type (beforeLoad context).
Syntax
Below is the syntax for using the `Form.insertField(options)` method. Note that this is not a functional example. For a complete script example, refer to the `N/ui/serverWidget Module Script Samples`.
“`javascript
// Add additional code
…
var form = serverWidget.createForm({
title: ‘Simple Form’
});
var field1 = form.addField({
id: ‘custpage_text’,
type: serverWidget.FieldType.TEXT,
label: ‘Text 1’
});
var field2 = form.addField({
id: ‘custpage_text2’,
type: serverWidget.FieldType.TEXT,
label: ‘Text 2’
});
form.insertField({
field: field2,
nextfield: ‘custpage_text’
});
“`