
[英]NetSuite Send an email to all users who have a specific role in suite script
[英]NetSUite primary role email
谢谢您的帮助。 我是Netsuite脚本的新手。 我需要一个工作流,该工作流操作脚本将获取角色为“主要联系人”的客户联系人的电子邮件地址,并在客户记录的自定义字段中设置此电子邮件地址。
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
}
}
}
你近了 应该这样做:
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。
抱歉。 我忘了联系方式多么奇怪。 最安全的方法是通过搜索:
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'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.