NetSUite主要角色电子邮件

时间:2016-01-26 16:43:45

标签: netsuite

我很感谢你的帮助。我是Netsuite Scripting的新手。我需要一个工作流,工作流操作脚本用于获取客户联系人的电子邮件地址,其中包含“主要联系人”角色,并在客户记录的自定义字段中设置此电子邮件地址。

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 
        }
    }

}

2 个答案:

答案 0 :(得分:2)

你很亲密。这应该做:

function getContactEmail() {
    var numItem = nlapiGetLineItemCount('contactroles');
    for (var i = 1; i <= numItem; i++) {
       if(nlapiGetLineItemValue('contactroles', 'role', i) != 14) continue; // the id for primary contact is 14 in my test account
       try{ //contact may be inactive
         var contactInfo = nlapiLookupField('contact', nlapiGetLineItemValue('contactroles', 'contact', i), ['email', 'company']);
         var roleEmail = nlapiGetLineItemValue('contactroles', 'email', i) || contactInfo.email;
         if(!roleEmail) continue;
         if(!contactInfo.company || contactInfo.company != nlapiGetRecordId()) continue; //maybe ok if not assigned to any company?

         nlapiSetFieldValue('custentity_email', roleEmail); //set the value of custom field with email address of the Contact which has 'Primary Contact' role 
         break;
       }catch(e){
         nlapiLogExecution('ERROR', "Looking up contact: "+ nlapiGetLineItemValue('contactroles', 'contact', i), e);
       }
    }
}    

请注意,您可以在https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2015_1/script/record/customer.html

处引用字段ID

答案 1 :(得分:0)

对不起。我忘记了奇怪的联系方式。最安全的方法是搜索:

function setContactEmail(){
  var contacts = nlapiSearchRecord('customer', null,
        [
            new nlobjSearchFilter('internalid',null, 'is', nlapiGetRecordId()),
            new nlobjSearchFilter('contactrole', 'contact', 'is', '-10'),
            new nlobjSearchFilter('isinactive', 'contact', 'is', 'F'),
            new nlobjSearchFilter('company', 'contact', 'is', nlapiGetRecordId())
        ],[
          new nlobjSearchColumn('email', 'contact')
        ]);
  if(contacts) nlapiSetFieldValue('custentity_email', contacts[0].getValue('email', 'contact'));
}