Hi there, I am working on writing an email capture...
# suitescript
n
Hi there, I am working on writing an email capture script and looking to take the attachment (csv) that's on the email and need to attach the csv file to a record in Netsuite. Does anyone know how to do that?
s
You would need to get the file off the case or wherever it's coming in, and prob use record.attach() to associate the file with the new record record.attach
e
Assuming you mean you are building an implementation of the Email Capture Plugin, then the
Email
instance which gets passed into your entry point has a
getAttachments()
method which returns an Array of
Attachment
instances, each of which has a
getValue()
method to return the file contents
which you could then use to create a new
File
and attach it to the appropriate
Record
n
Awww okay! So I would make it into a loop of sorts for the attachments to grab the values?
I'll give it a shot! Thank you both!!
e
I'd probably write something like:
Copy code
email.getAttachments().map(function (attachment) {
  return nlapiSubmitFile(
    nlapiCreateFile(attachment.getName(), attachment.getType(), attachment.getValue())
  );
}).forEach(function (fileId) {
  nlapiAttachRecord("file", fileId, recordType, recordId); 
});
a
You should be able to also just grab the file without having to read the content and create a file...
Untitled
e
Is an
Attachment
also a valid
File
?
I wouldn't expect that
a
yep...
e
Interesting
a
Now there is a bug where certain kind of attachments NetSuite miss identify them... but if you are sure your attachments would be CSV you can do something line this:
Untitled
From some Email Clients NetSuite is able to properly identify the Attachment Type, but for some it does not... and see those as BINARY which is not true... they are valid CSV...
n
oh woww thank you both so much, this helped out wonderfully!!