Saturday, June 15, 2019

SuiteScript > Create a Message Saved Search > Grab Results > Send Email

Below is  a sample code that creates a Message based saved search via script and looks for all the messages created today and then emails the result. You can also create a saved search in UI and reference that search via Script.

function search()

{

var Filters = new Array();

var id = '';
var type = '';
var author = '';
var subject = '';

Filters[0] = new nlobjSearchFilter('author', null, 'anyof', '-5'); // set the internal id  of the author, the criteria can be set according to requirement Please refer to SuiteScript Records Browser to see list of available filters and Columns for the Message Record
Filters[1] = new nlobjSearchFilter('messagedate', null, 'on', 'today'); 

var col = new Array();
col[0]= new nlobjSearchColumn('internalid');
col[1]= new nlobjSearchColumn('messagetype');
col[2] = new nlobjSearchColumn('author');
col[3] = new nlobjSearchColumn('subject');
  
var rec = nlapiSearchRecord('message',null, Filters, col);
 
for ( var i = 0; rec != null && i < rec.length; i++ )
{
var rec1 = rec[ i ];
var id = id + rec1.getValue('internalid');  // As required values for other fields such as Author, subject can be captured and sent via email
}

var id1 = id.split();

/* if the emails needs to be attached to any record create a record object
var records = new Object();
records['transaction'] = 'xxx';
*/

nlapiSendEmail('-5','xxxx@xxx.com',null,'searchresults','id1',null,null,records,null);

No comments:

Post a Comment