Hello, has anyone else been having issues sending ...
# suitescript
m
Hello, has anyone else been having issues sending attachments in emails in SS2.0? I have a function that renders a quote into a pdf using the render module, inserting the pdf file into an array and then giving that to the attachments option of nEmail.send but it throws an error "Wrong parameter type: options.attachments is expected as file.File[].". I checked the pdf I am trying to attach and it renders ok and is only 300kb so its not a size issue. Also tried attaching a generic image instead and getting the same message. Email sends fine if I don't try to attach anything
b
share your code. your error suggests you aren't putting Files into your attachment array
m
Copy code
quote = nRecord.load({ type:'estimate', id:quoteId });
			customerId = quote.getValue({ fieldId:'entity' });
			
			pdf = nRender.transaction({ entityId:quoteId, printMode:nRender.PrintMode.PDF  });
			
			email = nRender.mergeEmail({ templateId: templateId, transactionId: quoteId });
			
			payNowUrl = getPayNowUrl(quote);
			
			emailBody = email.body;
			emailBody = emailBody.replace(PAYNOW_LINK_PLACEHOLDER, payNowUrl);
			
			nEmail.send({ 
				author:senderId, 
				recipients:[customerId], 
				subject:email.subject, 
				body:emailBody, 
				attachments: [pdf],
				relatedRecords: {
					transactionId: quoteId,
				}
			});
b
that looks normal to me, you may want to try testing something more simple
i was using
Copy code
require(["N/file", "N/email", "N/record", "N/render"], function(
  file,
  email,
  record,
  render
) {
  var senderId = 3;
  var quoteId = 703;

  var quote = record.load({ type: "estimate", id: quoteId });
  var customerId = quote.getValue({ fieldId: "entity" });

  var pdf = render.transaction({
    entityId: quoteId,
    printMode: render.PrintMode.PDF
  });

  var emailBody = "test body";
  var emailSubject = "test subject";

  email.send({
    author: senderId,
    recipients: [customerId],
    subject: emailSubject,
    body: emailBody,
    attachments: [pdf],
    relatedRecords: {
      transactionId: quoteId
    }
  });
});
m
Thanks for trying that out. Yeah I will try calling the function in a simpler context on the account I am on
I think it does not like running in a Suitelet context or there is some other factor somewhere in my script influencing the object type because both your code and mine work fine in the debugger on the account
Thanks for your help
For anyone interested or runs into a similar issue: it turns out one of the custom modules my script is referencing was altering the base javascript object
Object.prototype.customFunction= function(){}
. This was causing the NetSuite Email module to not recognise the array object I was trying to pass in.