Hello all,
We have a Suitelet that seems to be ignoring additional filters we are adding to a saved search. Because we cannot yet combine saved searches (that improvement cannot come soon enough) we have to first run a saved search to get all the items we want to find in sales orders in our second search. First search, no problem. Second search we add to additional filters to the saved search. One is for the marketing campaign (works) and the second for the list of items which we put into an array from the first search. Suitelet runs, search runs but ALL items are shown not just items we filtered for. Dumped the search object to the log and boht filters are there. Only question was maybe the list was too big. Not sure of there is a limit. So, we hardcoded the list to three items. Ran again and STILL all items are show. log shows the correct search filters.
We have not idea why it is ignoring our second filter. We moved it first, still ignores it but grabs the second one. Stumped.
Here's the code
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/ui/serverWidget', 'N/record', 'N/search'],
function(ui, record, search) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} context
* @param {ServerRequest} context.request - Encapsulation of the incoming request
* @param {ServerResponse} context.response - Encapsulation of the Suitelet response
* @Since 2015.2
*/
function onRequest(context) {
var request = context.request;
var response = context.response;
var styleHeader = 'background-color: #d0e6b6;';
var styleEvenRow = 'background-color: #F0F0F0;';
var styleOddRow = 'background-color: White;';
var arrayItems = [];
try
{
var internalid = request.parameters.internalid;
}
catch(e)
{}
var currow = 0
if (internalid != null)
{
var curRowStyle = styleOddRow;
currow = currow + 1;
var mod = (currow+1)%2;
if (mod == 0)
{
curRowStyle = styleEvenRow;
}
campaignRec = record.load({
type: record.Type.CAMPAIGN,
id: internalid
});
var title = campaignRec.getValue({fieldId: 'title'});
var startdate = campaignRec.getValue({fieldId: 'startdate'});
var enddate = campaignRec.getValue({fieldId: 'enddate'});
var campaignid = campaignRec.getValue({fieldId: 'campaignid'});
var form = ui.createForm({
title: "Campaign Item Sales for " + title
});
html = '';
html = html + '<table cellspacing="0" cellpadding="5">';
html = html + '<tr style="font-weight: bold; text-align:right; vertical-align:bottom; ' + styleHeader + '"><td style="text-align:left">Item</td><td style="text-align:right">Sales</td><td style="text-align:right">Qty</td><td style="text-align:right">#Orders</td></tr>';
//get campaign items
itemSearch = search.load({id: 'customsearch_pe_mktcampaignitems'});
itemSearch.filters.push(search.createFilter({
name: 'custrecord_pe_mktcmpgnitem_campaign',
operator: search.Operator.IS,
values: internalid
}));
itemSearch.run().each(function(result) {
var cItem = result.getText({name: 'custrecord_pe_mktcmpgnitem_item'});
var garb = arrayItems.push(cItem);
return true;
});
//get campaign items sales
salesSearch = search.load({id: 'customsearch_pe_campaignitemsales'});
salesSearch.filters.push(search.createFilter({
name: 'leadsource',
operator: search.Operator.IS,
values: internalid
}));
salesSearch.filters.push(search.createFilter({
name: 'item',
operator: search.Operator.ANYOF,
values: ['070-121', '070-134']
}));
log.debug('salesSearch', salesSearch);
salesSearch.run().each(function(result) {
var item = result.getText({name: 'item', summary: 'GROUP'});
var sales = result.getValue({name: 'amount', summary: 'SUM'});
var qty = result.getValue({name: 'quantity', summary: 'SUM'});
var orders = result.getValue({name: 'tranid', summary: 'COUNT'});
html = html + '<tr style="' + curRowStyle + '"><td>' + item + '</td>';
html = html + '<td style="text-align:right">' + sales + '</td>';
html = html + '<td style="text-align:right">' + qty + '</td>';
html = html + '<td style="text-align:right">' + orders + '</td></tr>';
return true;
});
html = html + '</table>';
html = html + arrayItems;
form.addField({
id: 'htmlfield',
type: ui.FieldType.INLINEHTML,
label: "test"
});
form.updateDefaultValues({htmlfield: html});
response.writePage(form);
}
}
return {
onRequest: onRequest
};
});
Any help appreciated. Thanks!
Karen