Hi-
We have an after submit user event script that creates a task and marks it as complete every time that an outgoing email is sent to a customer or contact. The script only catches outgoing emails, so step one is to figure out if the message is outgoing or incoming. To do this we need to grab the messages internal ID, and run a search with the column 'isincoming'. The problem is that we keep getting the following error:
"An nlobjSearchFilter contains an invalid operator, or is not in proper syntax: internalid."
I have tried both--
var messageid = nlapiGetRecordId(); //Get Message internal ID
filters[0] = new nlobjSearchFilter('internalid','messages','anyof',messageid);
AND
filters[0] = new nlobjSearchFilter('internalid','messages','is',messageid);
I seem to get the error in both cases. Any ideas as to what I doing wrong???
--THE SCRIPT--
function emailtask()
{
nlapiLogExecution('DEBUG', 'Test Log');
var messageid = nlapiGetRecordId(); //Get Message internal ID
var filters = new Array();
filters[0] = new nlobjSearchFilter('internalid','messages','anyof',messageid); //Filter to this message only
var columns = new Array();
columns[0] = new nlobjSearchColumn('isincoming', 'messages', null); //pull only one column making it isinconning
var searchresults = nlapiSearchRecord('entity', null, filters, columns); //CREATING A Search RESULT OBJECT
if(searchresults!=null)
{
var searchresult = searchresults[0];
var icog = searchresult.getValue('isincoming', 'messages', null);
if(icog=='F') //only continue if message is outgoing)
{
var recipient = nlapiGetFieldValue('recipient');
var author = nlapiGetFieldValue('author');
var messageentity = nlapiGetFieldValue('entity');
var template = nlapiGetFieldValue('template');
var incomming = icog;
var emailbody=("recipient is: "+recipient+"author is: "+author+"messageentity is: "+messageentity+"template is: "+template+"incomming is: "+incomming);
nlapiSendEmail(25, 25, 'Task Email Script Fired', emailbody, null, null, null, null); //email changes to Matt Stryker
if (template=="")
template=52;
var messageid = nlapiGetRecordId(); //Get Message internal ID
var emailurl = ("https://system.netsuite.com/app/crm/common/crmmessage.nl?id="+messageid);
var newtask;
newtask = nlapiCreateRecord('task');
newtask.setFieldValue('title', 'Email Created Task');
newtask.setFieldValue('status', 'COMPLETE');
newtask.setFieldValue('assigned', author); //assign to email author
newtask.setFieldValue('custevent_emailurl', emailurl);
newtask.setFieldValue('company', messageentity); //set to entity of recipient of message
newtask.setFieldValue('custevent_templateused', template);
var newtaskid = nlapiSubmitRecord(newtask, true, true);
}//END IF INCOMMING IS FALSE
} //END IF SEARCHRESULTS ARE NOT NULL
} //end function email task