This topic contains 9 replies, has 0 voices, and was last updated by markjasonflores 7 years, 8 months ago.
-
AuthorPosts
-
March 7, 2017 at 11:34 am #1090
karennHello 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 + ‘
‘;
html = html + ‘
Item Sales Qty #Orders ‘;
//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 + ‘
‘ + item + ‘ ‘;
html = html + ‘
‘ + sales + ‘ ‘;
html = html + ‘
‘ + qty + ‘ ‘;
html = html + ‘
‘ + orders + ‘ ‘;
return true;
});
html = html + ‘
‘;
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
This is a cached copy. Click here to see the original post. -
March 7, 2017 at 12:01 pm #1091
david.smithvar cItem = result.getText({name: ‘custrecord_pe_mktcmpgnitem_item’});
The above line is getting the test of the item, not the value.
-
March 7, 2017 at 12:03 pm #1092
chanarbonHi karenn
Just wondering if
Code:
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’]
}));var resultCnt = 0;
log.debug(‘salesSearch’, salesSearch);
salesSearch.run().each(function(result) {
resultCnt++
return true;
});
returns the same resultCnt asCode:
salesSearch = search.load({
id: ‘customsearch_pe_campaignitemsales’
});var resultCnt = 0;
log.debug(‘salesSearch’, salesSearch);
salesSearch.run().each(function(result) {
resultCnt++
return true;
}); -
March 7, 2017 at 12:21 pm #1093
karennHi chanarbon,
No. the results are different as expected. The results are as if it is just ignoring the item filter. It is using the campaign filter.
Thanks!
Karen
david.smith replied on 03/07/2017, 12:22 PM: You need to use internalid values for the item filter.
-
March 7, 2017 at 12:22 pm #1094
karennHi Dave,
Text is what we want here.
Thanks!
Karen
-
March 7, 2017 at 12:30 pm #1095
chanarbonI actually agree with david.smith from the note that we mentioned on the comment. You should try using the internalid values and not the item code on the filter since the item is a select field and per consideration of the need, it should really be internalids and not item code.
-
March 7, 2017 at 12:33 pm #1096
karennBut if that was the issue, shouldn’t the search come back with nothing since no items will match? I am not seeing how that could be the issue
-
March 7, 2017 at 12:42 pm #1097
david.smithIn your code you should always use internalid values whenever possible. Text can be incorrect or duplicated (in general). The internalid will always be unique and is better for performance.
Items come back in your first search just fine. You just need to change that one line and everything else should be OK.
-
March 7, 2017 at 12:43 pm #1098
david.smithsorry, you do need to change this too
salesSearch.filters.push(search.createFilter({
name: ‘item’,
operator: search.Operator.ANYOF,
values: garb
}));
-
March 7, 2017 at 12:46 pm #1099
markjasonfloresOriginally posted by karenn
View Post
salesSearch.filters.push(search.createFilter({
name: ‘item’,
operator: search.Operator.ANYOF,
values: [‘070-121’, ‘070-134’]
}));
Hello Karen,
The item filter in transaction searches uses internalid.
To fix this issue:
1. Use internalid instead of text in the values
2. f you want to use text, you need to use a join. Try Item:name or something similar
-
AuthorPosts
You must be logged in to reply to this topic.