Hi,
We are trying to complete a technical proof of concept for a customer who wants to upload historical emails and attachments from Goldmine into their NetSuite account. According to the WebServices documentation this is possible. We are able to upload a message but when we try to enhance the code to include an attachment we get an error per the code below stating that name, type and folder are missing. According to our reading of the documentation, these should be optional if incoming=true.
Any ideas on what we maybe doing wrong?
Thanks,
Adrian.
====================================
When I try to add a message to an attachment it asking me for a folder name. To my understanding if I flag a message as incoming = true then the file attachment will automatically be saved in the "Attachments Received" folder. I'm not sure why I am getting an error saying that I need to have the folder name.
[Error]: [Code=NAME_TYPE_FLDR_FIELDS_REQD] missing required fields : name, type,
and folder
Here's my code for the addmessage function:
private void addMessage()
{
//This operation requires a valid session
this.login( true );
Message themessage = new Message();
//Promt user for customer id
RecordRef therecipient = new RecordRef();
_out.write( "Enter the customer id: ");
therecipient.internalId = _out.readLn();
themessage.recipient = therecipient;
//Prompt for message subject
_out.write( "Enter your subject here:");
themessage.subject = _out.readLn();
//Prompt for message
_out.write("Enter your message here:");
themessage.message = _out.readLn();
RecordRef theauthor = new RecordRef();
theauthor.internalId = "171";
themessage.author = theauthor;
themessage.incoming = true;
//Add an attachment
FileStream fs = System.IO.File.OpenRead("C:\\test.txt");
int size = (int)fs.Length;
System.Byte[] bytes = new Byte[size];
int offset=0;
while (size > 0)
{
int read = fs.Read(bytes, offset, size);
if (read <= 0)
throw new EndOfStreamException
(String.Format("End of stream reached with {0} info left to read", size));
size -= read;
offset += read;
}
thefile.content = bytes;
thefile.name = "test.txt";
thefile.fileType = MediaType._PLAINTEXT;
au.com.netsuite.webservices.File[] filearray = new au.com.netsuite.webservices.File[1];
filearray[0] = thefile;
themessage.mediaItemList = filearray;
WriteResponse response = _service.add(themessage);
if ( response.status.isSuccess)
{
_out.info("Message was added successfully");
}
else
{
_out.error("Message was not added:", true);
_out.error(getStatusDetails(response.status));
}
}
================================================
When we define folder as follows, we get a different error:
New code:
RecordRef thefolder = new RecordRef();
// Internal id of Attachments Received is -10
thefolder.internalId = "-10";
thefile.folder = thefolder;
We get the error message saying:
[Error]: [Code=INSUFFICIENT_PERMISSION] You do not have permissions to set a val
ue for element mediaitem.folder due to one of the following reasons: 1) The fiel
d is read-only; 2) An associated feature is disabled; 3) The field is available
either when a record is created or updated, but not in both cases.
Our next attempt was to define folder but not set a value due to the error above but this crashes the program with a null pointer exception.
Not sure where to from here. We are trying to do what the Outlook integration does so there is no reason why this should not work.
Thanks,
Adrian.