如何通过Suitescript 2.0在保存的搜索中应用多个过滤器?

问题描述 投票:0回答:1

我正在现有的已保存搜索中应用过滤器,但未应用。当我是Suitescripts的新手时,有人可以帮我解决这个问题吗?

过滤器:genderitem通过参数从Suitelet传递到此计划脚本:

var slfilters = runtime.getCurrentScript().getParameter({ name: 'custscript_searchfilter_report' });
  //
  // ─── MAIN FUNCTION───────────────────────────────────────────────────
  //
  function generateReport() {
    var slfilters = runtime.getCurrentScript().getParameter({
      name: 'custscript_searchfilter_report'
    });
    log.debug('slfilters', slfilters);

    if (!!slfilters) {
      slfilters = JSON.parse(slfilters);
    }
    log.debug('slfilters2', slfilters);

    //var getUser = runtime.getCurrentUser();

    var gender = slfilters.isgender
    log.debug('gender', gender)
    var item = slfilters.isItem
    log.debug('item', item)

    var item = getItems(item, gender);
    log.debug('items table', item)
    // return item;

    var xmlTemplateFile = file.load(3918);
    //var template = script.getParameter({ name: 'custscript_template' });
    var renderer = render.create();
    renderer.templateContent = xmlTemplateFile.getContents();
    var customSources = {
      alias: 'searchdata',
      format: render.DataSource.JSON,
      data: JSON.stringify({
        value: item,
      })
    };
    renderer.addCustomDataSource(customSources);

    var xml = renderer.renderAsString();
    var pdf = render.xmlToPdf({
      "xmlString": xml
    });

    email.send({
      author: 317,
      recipients: '[email protected]',
      subject: 'Item Report',
      body: 'Report Generated: ',
      attachments: [pdf]
    });
  }

  //
  // ─── SEARCH ───────────────────────────────────────────────────
  //
  function getItems(item, gender) {
    try {
      var itemSearch = search.load({
        id: 'customsearch_mx_itemsearch'
      });
      log.error('itemSearch', itemSearch)

      var defaultFilters = itemSearch.filters;
      var arrFilters = [];

      arrFilters.push(search.createFilter({
        name: 'custitem5', //gender
        operator: 'anyof',
        values: gender
      }));

      arrFilters.push(search.createFilter({
        name: 'itemid',
        operator: 'anyof',
        values: item
      }));

      defaultFilters = defaultFilters.concat(arrFilters);
      log.error('Updated Filters', defaultFilters)

      var results = itemSearch.run().getRange({
        start: 0,
        end: 150
      });

      results.map(function(x) {
        return {
          'category': x.getText({
            name: "custitem10",
            join: "parent"
          }),
          'season': x.getValue({
            name: "custitem11",
            join: "parent"
          }),
          'riselabel': x.getValue({
            name: "custitem_itemriselabel",
            join: "parent"
          }),
          'fit': x.getValue({
            name: "custitem9",
            join: "parent"
          }),
          'name': x.getValue({ //sku
            name: "itemid",
            join: "parent"
          }),
          'style': x.getValue({
            name: "custitem8",
            join: "parent"
          }),
          'inseam': x.getValue({
            name: "custitem7",
            join: "parent"
          }),
          'wash': x.getValue({
            name: "custitem_washname",
            join: "parent"
          }),
        };
      });
      return results;
    } catch (e) {
      log.error('error in getItems', e)
    }
  }
  return {
    execute: execute
  };
});
javascript arrays search suitescript2.0 saved-searches
1个回答
0
投票

在SuiteScript 1.0中,有一个nlobjSearch方法“ setFilters”。 SuiteScript 2.0似乎没有等效功能,但是您仍然需要以某种方式设置过滤器。看来这是缺少的步骤。也许尝试使用

将新的过滤器推到/代替当前的搜索过滤器
itemSearch.filters.push(defaultFilters);

不确定是否要保存搜索。希望对您有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.