This topic contains 9 replies, has 0 voices, and was last updated by markjasonflores 7 years ago.

  • Author
    Posts
  • #1090 Score: 0

    karenn
    • Contributions: 0
    • Level 1

    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 + ‘

    ‘;

    html = html + ‘

    ‘;

    //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 + ‘

    ‘;

    html = html + ‘

    ‘;

    html = html + ‘

    ‘;

    html = html + ‘

    ‘;

    return true;

    });

    html = html + ‘

    Item Sales Qty #Orders
    ‘ + item + ‘ ‘ + sales + ‘ ‘ + qty + ‘ ‘ + orders + ‘

    ‘;

    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.

  • #1091 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    var cItem = result.getText({name: ‘custrecord_pe_mktcmpgnitem_item’});

    The above line is getting the test of the item, not the value.

  • #1092 Score: 0

    chanarbon
    • Contributions: 0
    • Level 1

    Hi 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 as

    Code:
    salesSearch = search.load({
    id: ‘customsearch_pe_campaignitemsales’
    });

    var resultCnt = 0;

    log.debug(‘salesSearch’, salesSearch);

    salesSearch.run().each(function(result) {

    resultCnt++

    return true;
    });

  • #1093 Score: 0

    karenn
    • Contributions: 0
    • Level 1

    Hi 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.

  • #1094 Score: 0

    karenn
    • Contributions: 0
    • Level 1

    Hi Dave,

    Text is what we want here.

    Thanks!

    Karen

  • #1095 Score: 0

    chanarbon
    • Contributions: 0
    • Level 1

    I 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.

  • #1096 Score: 0

    karenn
    • Contributions: 0
    • Level 1

    But 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

  • #1097 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    In 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.

  • #1098 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    sorry, you do need to change this too

    salesSearch.filters.push(search.createFilter({

    name: ‘item’,

    operator: search.Operator.ANYOF,

    values: garb

    }));

  • #1099 Score: 0

    markjasonflores
    • Contributions: 0
    • Level 1

    Originally 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

You must be logged in to reply to this topic.