<@UBACK4NQH> Recipients should be an array of emai...
# suitescript
a
@Ben Tanner Recipients should be an array of email addresses, I'm not sure about IDs.
b
The internal ID or email address of the recipient(s). For multiple recipients, use an array of internal IDs or email addresses. You can use an array that contains a combination of internal IDs and email addresses. A maximum of 10 recipients (recipient + cc + bcc) is allowed.
a
Yep it says it handles both, however I only remember using that and get it working with an array of emails.
b
I'm not sure what evaluation NetSuite does to determine if a value is an id or an email address (probably basic email format checking). That's why I tried submitting an array of int and string values.
It would be a bummer if that's not actually supported.
a
I don't recall using that with IDs so maybe is because that has been broken for a long time? Maybe somebody else have this working with IDs.
b
I'm wondering/hoping someone has done that successfully.
a
You will find out there is a lot of thing theoretically supported in the Documentation but not in real life.
m
I've used arrays of IDs, arrays of email addresses, and a mix of both in the same array without issue. Is it possible you're pushing a null value/empty string into the array? That'd probably cause an error.
a
Post your email send function/code just in case somebody can spot something... and @MTNathan mentioned a very good point.
b
I've logged the array to check the values. Looks good.
a
Log your recipients array right before you use it with the email.send()
b
Here is the code that creates the array
Copy code
function getToRecipients(myRecord) {
    	log.debug({title: 'Checking for To recipients'});
    	
    	var recipientIds = [];
    	
    	var mainOnboardContact = myRecord.getValue({fieldId: 'custrecord_implementation_main'});
    	if (mainOnboardContact != '' && recipientIds.indexOf(parseInt(mainOnboardContact)) == -1)
    		recipientIds.push(parseInt(mainOnboardContact));
    	
    	var mainRosterContact = myRecord.getValue({fieldId: 'custrecord_implementation_rostering'});
    	if (mainRosterContact != '' && recipientIds.indexOf(parseInt(mainRosterContact)) == -1)
    		recipientIds.push(parseInt(mainRosterContact));
    	
    	var mppOnboardContact = myRecord.getValue({fieldId: 'custrecord_ob_mpp_onboarding_contact'});
    	if (mppOnboardContact != '' && recipientIds.indexOf(parseInt(mppOnboardContact)) == -1)
    		recipientIds.push(parseInt(mppOnboardContact));
    	
    	var mppRosterContact = myRecord.getValue({fieldId: 'custrecord_ob_mpp_roster_contact'});
    	if (mppRosterContact != '' && recipientIds.indexOf(parseInt(mppRosterContact)) == -1)
    		recipientIds.push(parseInt(mppRosterContact));
    	
    	var mathOnboardContact = myRecord.getValue({fieldId: 'custrecord_ob_math_onboarding_contact'});
    	if (mathOnboardContact != '' && recipientIds.indexOf(parseInt(mathOnboardContact)) == -1)
    		recipientIds.push(parseInt(mathOnboardContact));
    	
    	var mathRosterContact = myRecord.getValue({fieldId: 'custrecord_ob_math_roster_contact'});
    	if (mathRosterContact != '' && recipientIds.indexOf(parseInt(mathRosterContact)) == -1)
    		recipientIds.push(parseInt(mathRosterContact));
    	
    	var galOnboardContact = myRecord.getValue({fieldId: 'custrecord_ob_gal_onboarding_contact'});
    	if (galOnboardContact != '' && recipientIds.indexOf(parseInt(galOnboardContact)) == -1)
    		recipientIds.push(parseInt(galOnboardContact));
    	
    	var galRosterContact = myRecord.getValue({fieldId: 'custrecord_ob_gal_roster_contact'});
    	if (galRosterContact != '' && recipientIds.indexOf(parseInt(galRosterContact)) == -1)
    		recipientIds.push(parseInt(galRosterContact));
    	
    	if (recipientIds.length > 0)
    		log.debug({title: 'Recipients', details: recipientIds});
    		
    	return recipientIds;
    }
I'll work through more logging at different points. At least @MTNathan confirmed it should work.
m
I think I'm usually sending emails to employee records by ID, not necessarily contacts, but I'm almost certain I've used contact IDs as well (and I can't imagine that it would work for some record types but not others). What does the output of
recipientIds
look like when you're logging it?
s
Maybe the id's should be strings, not Ints. That could definitely be your problem.
b
I've tried both strings and ints with no difference. I added logging to the calling function and get a null array. It seems the return value is getting lost so I'll play with that.
a
Well, Contacts could be/have external email address and are not necessarily employees (they don't have an employee record in NetSuite), since the email.author when using IDs only allows the use of Employee IDs it is possible that Recipients only works with IDs(for employees) and email addresses for non-employees.
@Ben Tanner Anyways your problem is one search away, if all your IDs are Contacts IDs you can do an small search and get all those Contacts' Email Addresses and be done with it.
m
I've definitely also done what @alien4u is suggesting before, at least in my SS1.0 scripts where multiple recipients had to be a comma separated string of email addresses, but I don't think that should be necessary in SS2.x. @Ben Tanner, it sounds like you've maybe already tracked the problem down (null array), but report back if resolving that doesn't fix the error on
email.send()
- I'd be curious to know for sure where the limitations are for
recipients
.
a
I have also used an array of ids without issues
And email addresses. But not a mixture
b
Tracked the problem down to an if statement that was supposed to prevent errors and instead caused them. Checking the input parameter like this
if (recipients.length = 0) {…
ended up clearing the array right before the
email.send()
call. Gah I hate those little errors. To confirm for others, my testing showed no difference between passing an array with a single value or multiple values, ids formatted as strings or ints, ids for employees or contacts. All combinations worked once I resolved my error. Thanks again for the ideas.
👍 1