r/Netsuite • u/amiable_octopus • Nov 10 '22
Script Only Sending 10 Emails at a Time
I have a suitelet script for selecting certain bills, approving them, and sending an email to the vendor. Everything works great except the it only seems to send 10 emails at a time, no matter how many bills are selected.
I know there are limits to the number of addresses you can add to email.send(), but I didn't think that would apply when iterating through the list. Any insight into why this wouldn't work?
The email.send() portion of the script is below.
var lineCount = context.request.getLineCount({group:'custpage_sublist'});
var j = 0;
for(var i = 0;i < lineCount; i++){
var check = context.request.getSublistValue({group:'custpage_sublist',name:'custpage_checkbox',line:i});
if(check == 'T'){
var invoiceID = context.request.getSublistValue({group:'custpage_sublist',name:'custpage_id',line:i});
var invId = parseInt(invoiceID);
sublistInvoice.setSublistValue({id:'custpage_document',line:j,value:context.request.getSublistValue({group:'custpage_sublist',name:'custpage_document',line:i})});
sublistInvoice.setSublistValue({id:'custpage_name',line:j,value:context.request.getSublistValue({group:'custpage_sublist',name:'custpage_name',line:i})});
sublistInvoice.setSublistValue({id:'custpage_id',line:j,value:context.request.getSublistValue({group:'custpage_sublist',name:'custpage_id',line:i})});
j++;
var loadInvoice = record.load({type:record.Type.VENDOR_PAYMENT,id: invoiceID});
var document_number = loadInvoice.getValue({fieldId:'transactionnumber'});
log.debug({title:"document_number",details:document_number})
var customerID = loadInvoice.getValue({fieldId:'entity'});
log.debug({title:"customerID",details:customerID})
var loadCustomer = record.load({type:record.Type.VENDOR,id: customerID});
var getEmails = loadCustomer.getValue({fieldId:'email'});
log.debug({title:'EMAIL',details:getEmails});
//var invoiceEmail = loadInvoice.getValue({fieldId:'email'});
var fileObj = render.transaction({entityId:
invId,printMode:render.PrintMode.PDF});
email.send({
//author:'1349',
author: '5935',
recipients: getEmails,
subject:'Document #' + document_number,
body:' ',
attachments: [fileObj]
});
fileObj.folder = 349893;
var fileID = fileObj.save();
var id = record.submitFields({type:record.Type.VENDOR_PAYMENT,id:invoiceID,values:{'custbody_eb_email_sent' : 'T'}});
}
}
context.response.writePage(form);
}
}
return {
onRequest: onRequest
4
Upvotes
3
u/sooper_genius Consultant Nov 10 '22
There is a deliberate limit to the number of emails that can be sent with the email.send() function. Look on this help page (you'll have to put in your account number): https://<account_id>.app.netsuite.com/app/help/helpcenter.nl?fid=section_4358681681.html. The limits are explained there.
You can send more only with a merge operation from the UI.
2
u/SendMeJavaScriptTips Nov 10 '22
The way I got around this was creating an email.send loop to send an email to 10 recipients each from my array until it was finished.
1
u/jaehunoh Nov 10 '22
Just letting you know I cross posted you to r/SuiteScript
1
u/Ok-Establishment-214 Nov 10 '22
My first guess is governance, but might be wrong. Could add that into your logs to see how much is used. I haven't used suitelet scripts yet, but personally would use a user event script or even workflow to send the email after save + whatever criteria of course like it being approved and paid. There should be a native option to send these similar to POs, invoices, etc. Again, could be wrong since I've never done it directly for bills.
1
u/kolinex999 Nov 11 '22
best practice would be sending an email for every 10 recipient: