Managing the relationship between a Customer and its Contacts may seem straightforward in the UI, but when it comes to SuiteScript, there are important limitations you need to understand. The Contacts sublist (contactroles) on the Customer record is considered a static sublist, which means certain actions are not scriptable.
What You Cannot Do in SuiteScript:
Because the Contacts sublist is a static sublist, the following limitations apply:
- You cannot programmatically remove a Contact from the Customer's Contacts sublist using SuiteScript.
- Method like removeLine() will fail on this sublist.
- You may encounter errors such as: “You have attempted an invalid sublist or line item operation...”
This is expected behavior due to how manages static sublists.
What You Can Do:
While you cannot directly detach a Contact from the Customer through SuiteScript, there are still several supported actions:
1. Manually Manage Contacts in the UI
Admins can still add or remove Contacts from the Customer record directly within NetSuite.
2. Mark the Contact Record as Inactive
If the goal is to prevent the Contact from appearing on the Customer record or from being used, you can safely automate this approach.
Example: Marking a Contact Inactive Using SuiteScript 2.x
/**
* @NApiVersion 2 .x
* @NScriptType ScheduledScript
*/
define(['N/record', 'N/log'], function(record, log) {
function execute(context) {
var contactId = 123; // Replace with your Contact ID
try {
// Set the contact as inactive
record.submitFields({
type: record.Type.CONTACT,
id: contactId,
values: {
isinactive: true
}
});
log.debug({
title: 'Contact Inactivated',
details: 'Contact ' + contactId + ' marked as inactive.'
});
} catch (e) {
log.error({
title: 'Operation Failed',
details: e.message
});
}
}
return { execute: execute };
});
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.
Do you have another way on how to automate your transactions using SuiteScript? Feel free to share them here!