In our previous article, New to NetSuite | Understanding SuiteScript 2.x Modules, we explored the SuiteScript Modules and N/record module, New to NetSuite | N/record Module Overview, which is used to interact with records. Now, we will take a closer look at one of the members of N/record: Field.type Property.
The Field.type property is a read-only string property that returns a body or sublist field’s data type. For example: "text", "date", "currency", "select", or "checkbox".
Syntax
field.type
- field is a Field object returned by methods such as record.getField() or sublist.getField().
- .type reads the field’s type as a string.
- It is read-only, you can check it, but cannot assign a new value to it.
Sample Usage
The sample Script loads a Sales Order, gets a body field (memo) and a sublist field (item), then logs each field’s type. For sublist fields, use record.getSublistField() and provide a zero-based line number.
/**
* @NApiVersion 2 .1
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], (record, log) => {
const execute = () => {
const salesOrder = record.load({
type: record.Type.SALES_ORDER,
id: 123 // Replace with a valid Sales Order internal ID
});
// Body field: use record.getField()
const memoField = salesOrder.getField({
fieldId: 'memo'
});
log.debug({
title: 'Memo field type',
details: memoField.type // Example: "textarea"
});
// Sublist field: use record.getSublistField(), not getSublist().getField()
const itemField = salesOrder.getSublistField({
sublistId: 'item',
fieldId: 'item',
line: 0 // First item line; SuiteScript 2.x is zero-indexed
});
log.debug({
title: 'Item sublist field type',
details: itemField.type // Example: "select"
});
};
return { execute };
});
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. Oracle + 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.
Oracle + 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. Oracle + 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.
Oracle + 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.
To know more about deploying SuiteScript, check these New to NetSuite Articles.
In upcoming articles, we'll break down individual SuiteScript 2.x modules and explain how to use them effectively in your scripts in SuiteCloud Product Area. Stay updated by following the New to NetSuite > SuiteCloud category to receive notifications whenever new articles are published.