Hi Guyz, I want to send different mail to differen...
# suitescript
n
Hi Guyz, I want to send different mail to different person as per below code using Scheduled script. I have below code but it is sending mail to only first person Please help me correct it and it should send a different mail to different person of the Receipients! define(['N/search', 'N/record', 'N/email'], function(search, record, email) { function execute(context) { var leadSearchObj = search.create({ type: "lead", filters: [ ["stage","anyof","LEAD"], ], columns: [ search.createColumn({ name: "entityid", sort: search.Sort.ASC, label: "ID" }), search.createColumn({name: "altname", label: "Name"}), search.createColumn({name: "internalid", label: "Internal ID"}), search.createColumn({name: "custentity9", label: "Lead Owner"}), search.createColumn({ name: "formulanumeric", formula: "FLOOR({today}-{custentity12})", label: "Formula (Numeric)" }), search.createColumn({name: "custentity12", label: "Owner Update Date"}), search.createColumn({ name: "email", join: "CUSTENTITY9", label: "Email" }) ] }); var searchResultCount = leadSearchObj.runPaged().count; log.debug("leadSearchObj result count",searchResultCount); var sendMailLead = []; var leadName = []; var leadId = []; var ownerMailId = []; var updateDate = []; leadSearchObj.run().each(function(result){ leadId.push(result.getValue({name: "entityid", sort: search.Sort.ASC, label: "ID"})); leadName.push(result.getValue({name: "altname"})); sendMailLead.push(result.getValue({name: "custentity9"})); ownerMailId.push(result.getValue({name: "email", join: "CUSTENTITY9", label: "Email"})); updateDate.push(result.getValue({name: "custentity12"})); return true; }); sendMailto(ownerMailId,leadId,leadName,sendMailLead,updateDate,searchResultCount); } function sendMailto(rec,leadId,leadName,sendMailLead,updateDate,cnt){ for(var i=0;i<cnt;i++){ var body = 'Dear Lead Owner,\n This Lead was assigned to you on '+updateDate[i]+' .\n'+ 'There has been no activity since assigment.\n'+ 'If you have worked on it Please update the Follow Up Status.\n\n'; email.send({ author: 12345, attachments: '', recipients: rec[i], bcc: '', cc: '', subject: 'Lead Follow Up' +leadId[i]+'', body: body }); } } return { execute: execute }; });
b
you have some array abuse going on here
n
yes, I'm storing the id of record and mail id of person in the array from the saved search
b
dont make an array for each one of your column values
make one array of search results
or one array of objects
at this point, i also fear for your internal ids
n
will it send a different mail to every person present in the result then if i make an object of it
this is a scheduled script
b
non descriptive script ids like custentity12 are not what netsuite recommends
n
that is not the problem
the problem is sending a different mail to every person present in the array
there are 3 persons present in rec and the mail is sending to only one rec[0] not to other two persons that is the issue here!!!
b
your are iterating based off of an external count
normally you would iterate over the length of the array of your data
but you have multiple arrays, which hopefully have the same length
combining your data into an array of structures instead of parallel arrays will eliminate any confusion about mismatched arrays
n
yah all the array has same length
there will not be an array which wont have same length, and the main array is receipeints array
how can I send a different mail to every person prensent in the rec array???
b
there are 2 basic causes, you arent actually calling email.send 3 times
or your emails are not being delivered, which means you want to get started with Troubleshoot Undelivered Email
n
no the mail are being sent to only first person rec[0] but rec[1] and rec[2] are not getting mails, is there any prblem in script??
b
have you checked that email.send is being called 3 times
n
okay Thankyou!
r
First, please make sure that when you pass the "rec" value, where the ownerMailId array resides in, the values you expect are actually there. I don't see any issue with the sendMailto invocation, as it's called only once and then the for loop will iterate over the search results.