In NetSuite script functions search.lookupFields and record.submitFields() there is an option to pass multiple custom field scriptids as parameters.
e.g:
let fieldLookUp = search.lookupFields({
type: search.Type.SALES_ORDER,
id: '101',
columns: ['custbody_1', 'custbody_2', 'custbody_3', 'custbody_4']
});
record.submitFields({
type: record.Type.SALES_ORDER,
id: 101,
values: {
'custbody_1': 'Hello from custom field',
'custbody_2': 'Test',
'custbody_3': 254,
'custbody_4': '1'
}
});
But we cannot use a variable name instead of field IDs here. If we directly pass variable replacing the field ID, it will return script error. As a fix, we can pass each variable inside square brackets.
e.g:
const CUSTOM_FIELDS_OBJ = {
CUST_BODY1: 'custbody_1',
CUST_BODY2: 'custbody_2',
CUST_BODY3: 'custbody_3',
CUST_BODY4: 'custbody_4',
}
let fieldLookUp = search.lookupFields({
type: search.Type.SALES_ORDER,
id: '101',
columns: [
[CUSTOM_FIELDS_OBJ.CUST_BODY1],
[CUSTOM_FIELDS_OBJ.CUST_BODY2],
[CUSTOM_FIELDS_OBJ.CUST_BODY3],
[CUSTOM_FIELDS_OBJ.CUST_BODY4]
]
});
record.submitFields({
type: record.Type.SALES_ORDER,
id: 101,
values: {
[CUSTOM_FIELDS_OBJ.CUST_BODY1]: 'Hello from custom field',
[CUSTOM_FIELDS_OBJ.CUST_BODY2]: 'Test',
[CUSTOM_FIELDS_OBJ.CUST_BODY3]: 254,
[CUSTOM_FIELDS_OBJ.CUST_BODY4]: '1'
}
});