When a new contact is created from an existing customer and the preference Setup > Company > General Preferences > Pre-Populate Contact Address is checked, then the address on the contact record will default to the one on the customer record.
The requirement is to keep some of the fields from the pre-populated address, but clear the value in others. For example the City, State/Province and Country from the customer's address should be displayed on a new contact for this customer, however the Address 1 and Address 2 fields should be cleared.
This can be achieved by means of the Page Init Function of a client script. More information about the Page Init function can be found in SuiteScript : Understanding NetSuite Script Types : Client Scripts : Client SuiteScript Samples : Page Init Sample.
The Page Init Function needed in this scenario should perform the following steps:
- Check if the contact record is just being created.
- Check if the contact record is being created from an existing customer record.
- Set the fields, whose value must be cleared, to the empty string.
In order to check whether the contact record is just being created the type parameter of the Page Init function can be evaluated. The type parameter shows the mode in which the record is being accessed. More information about the type parameter can be found in SuiteCloud (Customization, Scripting, and Web Services) : SuiteScript : Understanding NetSuite Script Types : Client Scripts : Client Event Types.For example:
if (type == 'create') { ... }
Whether the contact record is created from an existing contact can be found by evaluating the Company field. If the record is just being created and the Company field is already populated, then the contact record is created from an existing customer record. An example of how this can be checked is the following:
//get the value of the Company field var company = nlapiGetFieldValue('company'); //check whether it is not empty if (company != null && company != '') { ... }
The Address 1 and Address 2 fields can be cleared, for example, as below:
nlapiSetFieldValue('addr1', ''); nlapiSetFieldValue('addr2', '');
Information on how to create a script record can be found in SuiteCloud (Customization, Scripting, and Web Services) : SuiteScript : Running a Script in NetSuite : Step 4: Create Script Record : Steps for Creating a Script Record.
No comments:
Post a Comment