NetSuite SS 2.0 – Attach File Object to Email Being Sent Keeps getting Error “Wrong parameter type: options.attachments is expected as file.File[].”

I am writing a script where I am trying to print a transaction and then email it. I keep getting the following error.

“Wrong parameter type: options.attachments is expected as file.File[].”

I can’t tell what is wrong with my code. Here is the snipped of code that is causing the issues. The email sends just fine if I don’t include the attachments parameter. Any help would be greatly appreciated.

var recID = 1213;
var userID = 1478;
var emailSender = 1478;
var emailSubject = "Test Email";
var emailBody = "This is a test.";
var mainRecipient = "test@test.com";
var additionalRecipients = null;
var recPDF = render.transaction({

entityId: recID,

printMode: render.PrintMode.PDF,
});
email.send({

author: author,

recipients: mainRecipient,

subject: emailSubject,

cc: additionalRecipients,

body: emailBody,

attachments: [recPDF],

relatedRecords: {

transactionId: recID

}

});
Rookie Asked on December 2, 2020 in SuiteScript.
Add Comment
3 Answer(s)

From the help, render.transaction() should be returning a file.File.  You could try saving your file and then loading with the file.load() to ensure it’s not actually something wrong with the file.

Intermediate Answered on December 2, 2020.

I have run the script with the SuiteScript debugger and I can verify that the render.transaction() is returning a file.File object.  I am trying to avoid saving the file to the File cabinet so it doesn’t eat up space because I don’t need it saved. I just want it emailed.  I have done this exact process with SuiteScript 1.0 and I am just trying to recreate with 2.0.

If it comes to where I need to save it so the email.send function with 2.0 will work properly, then I will need to do that and then I will delete the file after the email is sent, but I am trying to avoid those extra steps.

on December 2, 2020.

I did just try saving the file to the file cabinet and then loading it in the script and it still gave the same error.

on December 2, 2020.

I would also try giving the recPDF file more properties like a name (with an extension on it).  I have old code that looks very similar to yours and it works fine, also try making the id of the transaction you are rendering a string instead of a number.  For reference, this code worked fine:

var newInvId = newInv.save({
ignoreMandatoryFields: true
});
var invPdf = render.transaction({
entityId: newInvId,
printMode: render.PrintMode.PDF
});
email.send({
author: someIdHere,
recipients: someIdHere,
cc: ['someEmailHere@email.com'],
subject: 'Invoice #' + newInvNum,
body: 'Please open the attached file to view your Invoice. If you have any questions please contact _',
attachments: [invPdf],
relatedRecords: {
transactionId: newInvId
}
});

on December 2, 2020.

The recPDF object already has those when its rendered. Here is a screen shot of the data object in the script debugger.

RE: NetSuite SS 2.0 - Attach File Object to Email Being Sent Keeps getting Error

 

The id of transaction being rendered can’t be a string. It has to be an integer otherwise the render.transaction function throws an error.

on December 2, 2020.

What type of script is performing this action, I will try to reproduce on test instance and see if I get the same thing with your code?

on December 2, 2020.

It running in a Suitelet. It sends the email just fine when I don’t include the attachments parameter, but with the attachments parameter I get the error.

on December 2, 2020.

Hi  daBears38235,

I’ve just tried your code in the script debugger and it worked fine.

Does it work in the script debugger for you?

Thanks,

Chris

on December 2, 2020.

I have run my suitelet in testing mode and am using the debugger to debug it.

on December 2, 2020.
Add Comment

Hi,

As a quick test, could you try this:

attachments: recPDF,

Thanks,

Chris

Intermediate Answered on December 2, 2020.

When I try it that way, I get the following error:

“Wrong parameter type: options.attachments is expected as Array. “

on December 2, 2020.
Add Comment

I figured out my issue.  I have a library file module that I had added to my Suitelet. When I removed the library file module from the Suitelet my code worked fine. So something with the library file is conflicting.  That will be a different issue that I will need to figure out, but at least I got this working now. Thanks guys for helping me debug.

Rookie Answered on December 2, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor