// sampleFieldChanged.js
// Author: Brian Taylor and Adam Torman
// Date: 03/03/2004
/* This function is designed to test the Disable SFA checkbox to determine if it has been checked and if so, disable the salesrep, territory, and sales rep phone fields automatically.  If the use selects the Disable SFA checkbox later, the function sampleFieldChanged will be called with the Validate Field function to disable or enable the salesrep, territory, or sales rep phone fields appropriately. */
 
function pageInit()
{
// This function is designed to test the Disable SFA checkbox to determine if it has been
// checked and if so, disable the salesrep, territory, and sales rep phone fields
// automatically.  If the use selects the Disable SFA checkbox later, the function
// sampleFieldChanged will be called with the Validate Field function to disable or
// enable the salesrep, territory, or sales rep phone fields appropriately.
// create a variable to hold the Disable SFA value
var x = nlapiGetFieldValue('custentity_disable_sfa');
// alert("The value of the Disable SFA field is " + x);
// Test to determine if the Disable SFA value is True and if so, disable the three fields
if (x == 'T') 
{
nlapiDisableField('salesrep', x);
nlapiDisableField('territory', x);
nlapiDisableField('custentity_sales_rep_phone', x);
}
return true;
}
function sampleFieldChanged(type, name)
{
// This is an example of using the disable/enable fields feature.  This particular example is 
// based on the Customer record, and disables/enables both standard and custom fields.
// Using the disable/enable field nlapi for line items follows similarly. This example
// requires the addition of two Customer custom fields: Disable SFA (a checkbox field) 
// and Sales Rep Phone (a phone number field sourced from the Sales Rep record). On 
// the Field Changed event, the status of the Disable SFA checkbox field is checked, and 
// the standard fields, Sales Rep and Territory, and the custom field, Sales Rep Phone, 
// are disabled/enabled. The custom code must also match the custom field IDs given 
// upon creation.

if (name == 'custentity_disable_sfa')
{
var disable = nlapiGetFieldValue('custentity_disable_sfa') == 'T'?true:false;
nlapiDisableField('salesrep', disable);
nlapiDisableField('territory', disable);
nlapiDisableField('custentity_sales_rep_phone', disable);
}
}
