<!channel> ¿Anyone has experience using the nlapiS...
# suitescript
n
@channel ¿Anyone has experience using the nlapiSendEmail function on Scheduled Scripts?. ¿Has it worked for anybody?
a
it works great
n
@andrewh, ¿can you share a snippet and/or any specific configurations needed in the environment?
i
Are you doing it on SB or PROD? Scheduled scripts usually don't send emails on SB.
n
@igorp Sandbox. ¿Also, do you know if there is any official documentation regarding this behavior?
a
in sandbox emails will only send to the current user, this is by design so you don't send erroneous emails from a testing environment
make sure you can receive emails to the email being used for login
ahhhhhh, okay ahora veo tu problema
I didn't realize you are in sandbox - the current user when running a scheduled script is System (you can't get the email)
so.... this won't work for you in sandbox because it's from a scheduled script - pop a test script into production to validate that it will actually send (or put it in some other script in sandbox)
n
@andrewh, thank you very much for the information!. The way I was able to verify (in Sandbox) that the my development was able to send e-mails through a Scheduled Script was by using the Script debugger.
@andrewh ¿do you know if there is any official documentation about this?
a
email is always a tricky thing to setup. in my case even in PROD with dev acc it does not work. You may need a setting change....
n
Actually @arindam, based on @andrewh's comment
I didn't realize you are in sandbox - the current user when running a scheduled script is System (you can't get the email)
Shouldn't PROD work in the same way when sending emails from Scheduled scripts? Which makes me think that emails won't be sent either, and that may be why it doesn't work in PROD for you @arindam; BTW, ¿can you share these settings?
a
Setup -> Company -> Email Preference. Then (Sandbox and Release Preview) tab. Try diffent setting.
a
@Norberto Soriano you got a scheduled script to email via Sandbox using the debugger, righteous!
do you mind sharing that code?
did you literally just schedule on demand in the debugger or something else?
n
@andrewh, this is the snippet code you can use in your Scheduled script, please note that sender, recipients, subject and body values are gathered from a Script deployment parameters.
Copy code
var sender     = nlapiGetContext().getSetting('SCRIPT', 'send'); //  sender
var recipients = nlapiGetContext().getSetting('SCRIPT', 'recp'); //  recipients
var subject    = nlapiGetContext().getSetting('SCRIPT', 'subj'); //  subject
var body       = nlapiGetContext().getSetting('SCRIPT', 'body'); //  body

recipients = recipients == null ? new Array() : recipients.split(',');

nlapiLogExecution('DEBUG', 'sender',      sender);
nlapiLogExecution('DEBUG', 'recipients',  recipients);
nlapiLogExecution('DEBUG', 'subject',     subject);
nlapiLogExecution('DEBUG', 'body',        body);

nlapiSendEmail(sender, recipients, subject, body);
a
@Norberto Soriano Think you tagged the wrong person
n
@andrewh, yes I scheduled on demand on the debugger. In order to achieve this latter you have to do the following: 1. Set the STATUS of your Script Deployment record to +Testing+. 2. Open the Script Debugger and select to debug and existing script; a new popup window should show up with your Scheduled script. Sorry if I don't attach some screenshots but I'm in the middle of something.
Sorry @ahomsher, my bad!
a
no worries, thanks for the info