using PHP add web services operation:
require_once '../NSPHPClient/NetSuiteService.php';
$service = new NetSuiteService();
$imgPath = 'C:\Documents and Settings\hguerrero\My Documents\HelloWorld.doc'; //specify the file path
$imgContents = base64_encode(file_get_contents($imgPath)); //get the contents of the file
$file = new File();
$file->folder = new RecordRef();
$file->folder->internalId = "-15";
$file->name = 'HelloWorld.doc';
$file->fileType = '_WORD';
$file->attachFrom = '_computer';
$file->content = $imgContents;
$messageMediaItem = new MessageMediaItemList();
$messageMediaItem->mediaItem = $file;
$message = new Message();
$message->author = new RecordRef();
$message->author->internalId = "1";
$message->author->type = 'customer';
$message->recipient = new RecordRef();
$message->recipient->internalId = "384";
$message->recipient->type = 'contact';
$message->messageDate = '2012-03-23T00:50:39.301Z';
$message->subject = "case3242423";
$message->message = "Hello, This is a test.";
$message->emailed = "true";
$message->activity = new RecordRef();
$message->activity->internalId = '493';
$message->activity->type = 'supportCase';
$message->mediaItemList = $messageMediaItem;
$addRequest = new AddRequest();
$addRequest->record = $message;
$addResponse = $service->add($addRequest);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD MESSAGE WITH FILE ATTACHMENT TO THE CASE ERROR";
} else {
echo "ADD MESSAGE WITH FILE ATTACHMENT TO THE CASE SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
Note: You can attach a file of up to 10 MB only.
No comments:
Post a Comment