Pulling my hair out on trying to attach an email m...
# suitescript
d
Pulling my hair out on trying to attach an email message to an invoice record. I thought we could just send the email and use the "relatedRecords" option to attach it to a transaction record? Anybody see anything wrong with this simple email send? It won't attach to my invoice record.. thanks for helping
n
Read the help : "email.send(options)"
d
I did that of course. Email is sending fine, just not attaching to the record..
j
Code looks fine. I'm assuming the email is being received, and it's just not visible under communication -> messages on the invoice record. the invoiceId variable in your example is the invoice internal id correct?
n
Check what type of info the "relatedRecords" param is
d
@JohnnyC Yes, that's correct. InvoiceId is the internal id and it's not showing up under messages. I tried attaching it to just entity (contact) record but neither seems to work
n
Copy code
//Add additional code 
.
var senderId = -5;
var recipientEmail = <mailto:'notify@myCompany.com|'notify@myCompany.com>';
var timeStamp = new Date().getUTCMilliseconds();
var recipientId = 12;
var fileObj = file.load({
    id: 88
});
email.send({
    author: senderId,
    recipients: recipientId,
    subject: 'Test Sample Email Module',
    body: 'email body',
    attachments: [fileObj],
    relatedRecords: {
           entityId: recipientId,
            customRecord:{
                  id:recordId,
                  recordType: recordTypeId //an integer value
                  }
      }
});
...
This is the sample from help.
d
@Nairolf Ok, but that uses an entity Id and custom record. How do I attach it to a invoice / transaction record? I am creating the invoice in the first step and retrieve the Id. For testing purposes however I am just hard coding it. It's the invoice id shown in the url
j
@Dan P have you tried declaring your variable as a string.
d
@JohnnyC Yes I have tried that as well
n
hum... you're log as admin right?
d
@Nairolf Admin, correct
n
don't put the comma after "invoiceId }"
d
@Nairolf no difference...
n
I guessed so, it was more to make sure... As @JohnnyC said, everything looks good. Did you try to execute it in the debugger to see what is going on?
d
@Nairolf Yep, executing through debugger. No errors.. email is sent with attachment but nothing in communication -> messages on the invoice record. Very frustrating. I am in sandbox but that should work there too, I presume.
n
Hooooo sandbox... I see... Are you able to try it in a production env.?
d
I can try but it would defeat the purpose of testing all code in Sandbox and having to explain to client it only works in production..
n
I agree... but sandbox, as you know, there are not very stable 😞
d
@Nairolf @JohnnyC Ok, seriously. This is the dumbest thing. Exact same code works like a charm in Production. How is that even possible that it won't work in Sandbox? They recently did a refresh so all settings are the same.. How frustrating...
j
Weird... I had to give it a try and I have no issue on my sandbox account. My sandbox is about a month old since last refresh. I'll have to watch for this on next refresh.
n
We have so many issues with our sandboxes... Thanks for the feedback @Dan P. Good luck for your project!
d
@Nairolf Thank you. I appreciate your feedback. @JohnnyC Very strange indeed. Thanks for testing it and letting me know. I am a bit baffled myself.
👍 1