Description: Ability to clear the value on a field using SuiteScript features.
Solution
Is necessary to load a existent record and to also submit after clearing the values
- Navigate to Customization > Scripting > Scripts > New
- Click the (+) icon to upload the Script File with the sample code below
- Click Create Script Record
- Click Suitlet as the 1.0 Script Type
- Basic Information:
- Name: Enter Script Name
- ID:Enter the Script ID
- Function:Enter clearFieldOnRecord
- Click Save & Deploy
- Basic Information:
- Title: Enter Clear Field
- ID: Enter Deployment ID
- Status:Select Released
- Log Level:Select Debug
- Execute As Role:Select Administrator
- Click Save
Example Using SuiteScript 1.0:
/**
* Module Description
*
* Version Date Author Remarks
* 1.00 DD/MM/YYYY author SA
*
*/
/**
* @param {nlobjRequest} request Request object
* @param {nlobjResponse} response Response object
* @returns {Void} Any output is written via response object
*/
function clearFieldOnRecord(request, response) {
try {
var recTrans = nlapiLoadRecord('salesorder', 157);
// Using JS null keyword
recTrans.setFieldValue('custbody_field', null);
// Passing a empty string
recTrans.setFieldValue('custbody_field', '');
nlapiSubmitRecord(recTrans);
} catch (error) {
nlapiLogExecution('DEBUG', 'The package sublist is empty', '0');
}
}
2.Example SuiteScript 2.0.
- Navigate to Customization > Scripting > Scripts > New
- Click the (+) icon to upload the Script File with the sample code below
- Click Create Script Record
- Basic Information:
- Name: Enter Script Name
- ID:Enter the Script ID
- Click Save & Deploy
- Basic Information:
- Title: Enter Clear Field
- ID: Enter Deployment ID
- Status:Select Released
- Log Level:Select Debug
- Execute As Role:Select Administrator
- Click Save
/**
* @NApiVersion 2.0
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/record']
/**
* @param {record} record
*/, function (record) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function clearFieldOnRecord(context) {
try {
var salesOrder = record.load({
type: record.Type.SALES_ORDER,
id: 157,
isDynamic: true
});
// Using JS null keyword
salesOrder.setValue({
fieldId: 'memo',
value: null
});
// Passing a empty string
salesOrder.setValue({
fieldId: 'memo',
value: ''
});
var recordId = salesOrder.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
log.debug({ title: 'recordId', details: recordId });
} catch (error) {
log.debug({ title: 'Catch Error', details: error });
}
}
return {
onRequest: clearFieldOnRecord
};
});