使用 SuiteScript 的 Netsuite 逾期提醒
Netsuite Past Due Reminder using SuiteScript
脚本完成!感谢所有回复的人:)
/*
* 作者:劳拉·米切克
* 日期: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);
}
}
}
虽然有很多方法可以用于此目的,但我认为您的计划脚本方法会很好用。您可以通过将 8 天的计算卸载到您的搜索过滤器来确定要发送哪些电子邮件的逻辑,而不是手动尝试计算。我会在搜索类似以下内容时使用过滤器:
new nlobjSearchFilter('custentity_dayssincelastemailed', null, 'before', 'previousOneWeek');
请参阅标题为搜索日期过滤器 的帮助文章,详细了解您可以在过滤器中使用日期做什么。
在那之后,我相信您应该能够创建一个电子邮件模板并在您的代码中使用它来设置电子邮件的标题和样板文件 body。
我不太确定,对你来说可能更困难的是你的 A/R 老化依恋。不确定我是否使用过附加语句。
如果您要使用预定脚本,则需要收集要检查的记录。如果这些是客户记录,请务必设置 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);
我通常喜欢将我的 content/body 创建代码移动到单独的函数中,但这并不重要,具体取决于脚本的复杂程度。例如,我有几个脚本执行大量处理,必须逐条记录地发送一些信息,但也会向其他人发送 "digest" 类型的电子邮件。想想客户和客户经理。虽然设置一切以处理这两种情况很痛苦,但具有电子邮件内容生成功能却更清晰易读。
您不需要编写脚本来实现这个简单的要求。您所需要的只是保存的搜索和工作流程。这里的关键是您需要在保存的搜索中提出正确的标准。一旦您拥有正确的已保存搜索,您就可以将工作流程的启动设置为 运行 on Scheduled 并选择频率。使用“发送电子邮件”操作将电子邮件发送给客户,一切顺利。
此外,您可以从已保存的搜索中将客户记录加入消息字段,这样您就可以查看上次发送电子邮件的时间。
您可能还需要电子邮件模板。
脚本完成!感谢所有回复的人:)
/* * 作者:劳拉·米切克 * 日期: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);
}
}
}
虽然有很多方法可以用于此目的,但我认为您的计划脚本方法会很好用。您可以通过将 8 天的计算卸载到您的搜索过滤器来确定要发送哪些电子邮件的逻辑,而不是手动尝试计算。我会在搜索类似以下内容时使用过滤器:
new nlobjSearchFilter('custentity_dayssincelastemailed', null, 'before', 'previousOneWeek');
请参阅标题为搜索日期过滤器 的帮助文章,详细了解您可以在过滤器中使用日期做什么。
在那之后,我相信您应该能够创建一个电子邮件模板并在您的代码中使用它来设置电子邮件的标题和样板文件 body。
我不太确定,对你来说可能更困难的是你的 A/R 老化依恋。不确定我是否使用过附加语句。
如果您要使用预定脚本,则需要收集要检查的记录。如果这些是客户记录,请务必设置 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);
我通常喜欢将我的 content/body 创建代码移动到单独的函数中,但这并不重要,具体取决于脚本的复杂程度。例如,我有几个脚本执行大量处理,必须逐条记录地发送一些信息,但也会向其他人发送 "digest" 类型的电子邮件。想想客户和客户经理。虽然设置一切以处理这两种情况很痛苦,但具有电子邮件内容生成功能却更清晰易读。
您不需要编写脚本来实现这个简单的要求。您所需要的只是保存的搜索和工作流程。这里的关键是您需要在保存的搜索中提出正确的标准。一旦您拥有正确的已保存搜索,您就可以将工作流程的启动设置为 运行 on Scheduled 并选择频率。使用“发送电子邮件”操作将电子邮件发送给客户,一切顺利。
此外,您可以从已保存的搜索中将客户记录加入消息字段,这样您就可以查看上次发送电子邮件的时间。
您可能还需要电子邮件模板。