脚本已完成!感谢所有回复的人:)
/ * *作者:Laura Micek *日期:5-13-15 *目的:此脚本创建一个已保存的搜索,以便提取发送电子邮件所需的信息,以提醒客户 *他们的帐户已过期。保存的搜索确保客户超过11天或更长时间,检查是否存在 *免除过期提醒,并且他们的帐户余额大于1.一旦保存的搜索运行,它将循环通过 *满足这些要求的客户,它将使用过去的日子来确定是否需要发送电子邮件。电子邮件会 *只有在截止日期等于11或过期天数减去11后才会被发送,由8等于0表示它具有 *自上次通知后8天。 * /
function email_late_customers(type) {
//variables
var send_from = 22730; // Internal ID of NS User
//setup filters and result columns for a customer saved search
var filters = new Array();
filters[0] = new nlobjSearchFilter('daysoverdue',null,'greaterthanorequalto',11);
filters[1] = new nlobjSearchFilter('custentitypastdueremind',null,'is', 'F');
filters[2] = new nlobjSearchFilter('balance',null,'greaterthan', 1);
var columns = new Array();
columns[0] = new nlobjSearchColumn('internalid');
columns[1] = new nlobjSearchColumn('email');
columns[2] = new nlobjSearchColumn('daysoverdue');
//run saved search and loop thru results
var customers = nlapiSearchRecord('customer',null,filters,columns);
for (var i = 0; customers != null && i < customers.length; i++) {
//grab all the customer data
var this_customer = customers[i];
var cust_id = this_customer.getValue('internalid');
var send_to = this_customer.getValue('email');
var getpastduedays = this_customer.getValue('daysoverdue');
//this is the check to see if the amount of days is over 11 to see if another email needs to be sent.
if(getpastduedays > 11) {
var checkPastDue = (getpastduedays - 11) % 8;
}
/*
if the above checkPastDues evaluates to zero then it has been 8 days since the last notification, this is the other condition to send an email. The first being that the customer is 11 days past due.
*/
if(getpastduedays == 11 || checkPastDue == 0) {
//email subject
var subject = 'Your Account is Past Due';
// create body text
var body = 'Hello, \r\r';
body += ' This is a reminder that your account is currently past due. Attached is a current detailed aging of your account for your reference.\r\r ';
body += ' Can you please review and let me know the status of payment?\r\r';
body += ' Your prompt attention to this matter would be greatly appreciated. If you have any questions reguarding this account, please ';
body += ' contact us as soon as possible. Any questions or invoice copy requests can be email to ar@doubleradius.com.\r\r';
body += ' If payment has been recently been made, please accept our thanks and ignore this reminder.\r\r';
body += 'Thank You!\r\r';
//setup filters and result columns for a transaction saved search
var filters = new Array();
filters[0] = new nlobjSearchFilter('status',null,'is', 'CustInvc:A');
filters[1] = new nlobjSearchFilter('type',null,'is', 'CustInvc');
filters[2] = new nlobjSearchFilter('email',null,'is', send_to);
filters[3] = new nlobjSearchFilter('mainline',null,'is', 'T');
var columns = new Array();
columns[0] = new nlobjSearchColumn('internalid');
//run saved search and loop thru results
var transactions = nlapiSearchRecord('transaction',null,filters,columns);
var invoices = [];
for (var i = 0; transactions != null && i < transactions.length; i++) {
//grab all the transaction data
var this_transaction = transactions[i];
invoices[i] = this_transaction.getValue('internalid');
}
//print the statement to a PDF file object
var attachment = [];
for (var i = 0; invoices != null && i < invoices.length; i++) {
attachment[i] = nlapiPrintRecord('TRANSACTION',invoices[i],'DEFAULT',null);
}
//send the PDF as an attachment
nlapiSendEmail(send_from,/*send_to*/ 'lauram@doubleradius.com', subject, body, null, null, null, attachment);
}
}
}
答案 0 :(得分:1)
您不需要脚本来实现这个简单的要求。您只需要保存的搜索和工作流程。这里的关键是你需要在保存的搜索中找到正确的标准。获得正确的已保存搜索后,您可以将工作流程的“启动”设置为“已计划”并选择频率。使用“发送电子邮件”操作将电子邮件发送给客户,您就可以开始使用了。
此外,通过保存的搜索,您可以将客户记录加入消息字段,这样您就可以检查上次发送的电子邮件的时间。
您可能还需要电子邮件模板。
答案 1 :(得分:0)
虽然您可以使用许多方法,但我认为您的预定脚本方法可以正常工作。您可以通过将8天计算卸载到搜索过滤器来制定识别要发送的电子邮件的逻辑,而不是手动尝试计算。我会在搜索类似的内容时使用过滤器:
new nlobjSearchFilter('custentity_dayssincelastemailed', null, 'before', 'previousOneWeek');
请参阅标题为搜索日期过滤器的帮助文章,详细了解您可以在过滤器中使用日期执行的操作。
之后,我相信你应该能够创建一个电子邮件模板,并在你的代码中使用它来设置电子邮件正文的标题和样板。
我不太确定,对你来说可能更困难的是你的A / R Aging附件。不确定我是否使用过附加语句。
答案 2 :(得分:0)
如果您要使用预定脚本,则需要收集要检查的记录。如果这些是客户记录,那么一定要设置searchFilters和searchColumns返回然后收集结果。
// set Customer record filters and columns to return
var filters = new Array();
filters.push( new nlobjSearchFilter('isActive', null, 'is', 'F') );
filters.push( new nlobjSearchFilter('someotherfield', null, 'isempty') );
var cust_cols = new Array();
cust_cols.push( new nlobjSearchColumn('companyname') );
cust_cols.push( new nlobjSearchColumn('someotherfield') );
// now get the records that fit your filters and return the cols specified
overdue_customers = nlapiSearchRecord('customer', null, searchfilter, columns);
我通常喜欢将我的内容/正文创建代码移动到单独的函数中,但根据脚本的复杂程度,它实际上并不重要。例如,我有几个脚本需要进行大量处理,必须逐个记录地发送一些信息,但也会向其他人发送“摘要”类型的电子邮件。想想客户和客户经理。虽然设置所有内容以处理具有电子邮件内容生成功能的两种情况都是一种痛苦,但是更加安全和易于阅读。