I would appreciate your help please. I am new to Netsuite Scripting. I need a workflow that workflow action script to get email address of the customer contact with role 'Primary Contact'and set this email address on custom field on the Customer record.
function getContactEmail() {
var numItem = nlapiGetLineItemCount('contactroles');
for (var i = 1; i <= numItem; i++)
{
var contact_rec = nlapiGetLineItemValue('contactroles', 'contact', i);
// get all the contact name of the contacts of the customer
var contactEmailAddress = nlapiGetLineItemValue('contactroles', 'email', i);
// get the e-mail address of the contact
var contactRole = nlapiLookupField('contact', contact_rec, 'contactrole');
// get the internal ID of the role of that particular contact from the customer
if (contactRole == '-10') //check is the role is 'Primary Contact' or not.
{
nlapiSetFieldValue('custentity_email', contactEmailAddress);
//set the value of custom field with email address of the
//Contact which has 'Primary Contact' role
}
}
}