We have customer records in NetSuite CRM module with additional custom records linked to the customer record. We have a custom field on customer record "customer status".
Based on customer status we want to disable new custom record (in this case new service record) button. I am able to use beforeLoad script to disable button on main customer record but similar approach fails when I try to disable button associated with linked record.
/**
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(["N/log", "N/ui/serverWidget"], function(log,ui) {
function disableNewCaseButton(context){
if (context.type == context.UserEventType.VIEW){
var customerStatus = context.newRecord.getValue({"fieldId" : "custentitycustomer_status"});
if (customerStatus !== 1){
var newButton = context.form.getButton({
id: 'newrecrecmachcustrecordso_customer_name'
})
try{
newButton.isDisabled = true;
}
catch(e){
log.debug({
title : "error",
details: e
});
}
}
return;
}
}
return {
beforeLoad: disableNewCaseButton
}
});
I don't believe there is any API supported way to do this.
If you want to resort to DOM hackery, you could use a client script to hide it:
Keep in mind that there is no guarantee this won't break in a future NetSuite updates.
Another approach could be to leave the button, but use a Workflow or Script on the linked record to prevent it from saving if the customer status is not valid.