简体   繁体   English

SuiteScript 2.0保存的搜索过滤器:添加不在事务中的字段

[英]SuiteScript 2.0 Saved Search Filters: Adding Fields not in the Transaction

I am trying to run a saved search and add a filter to it that adds fields from associated records, but not the return type of transaction. 我正在尝试运行已保存的搜索并向其添加一个过滤器,用于添加关联记录中的字段,但不会返回事务的返回类型。 I am assuming that this will be a join but not exactly sure how this works. 我假设这将是一个连接,但不完全确定这是如何工作的。 The search is done in a Map Reduce script and it is supposed to do the following: 搜索是在Map Reduce脚本中完成的,它应该执行以下操作:

Find items in transactions with the same name and different class type. 查找具有相同名称和不同类类型的事务中的项目。 The Saved search looks for Sales Orders that are still open and the item name and class are the variables. 已保存的搜索查找仍处于打开状态且项目名称和类是变量的销售订单。 I have that information readily available in the getInputData function but am running into problems adding the filter. 我在getInputData函数中可以获得该信息,但是在添加过滤器时遇到了问题。 How should that look? 那怎么样? I have this as the code: 我有这个代码:

var mySearch = search.load({ id: 'customsearch_so_itemclassid' });
mySearch.filters.push(search.createFilter({ name: 'itemid', join: 'item', operator: 'IS', values: [itemName] }));
mySearch.filters.push(search.createFilter({ name: 'class', join: 'item', operator: 'ISNOT', values: [itemClass] }));

I did have the filter look like this: 我确实有过滤器看起来像这样:

var mySearch = search.load({ id: 'customsearch_so_itemclassid' });
mySearch.filters.push(search.createFilter({ name: 'itemid', operator: 'IS', values: [itemName] }));
mySearch.filters.push(search.createFilter({ name: 'class', operator: 'ISNOT', values: [itemClass] }));

Can anyone point to exactly why this is not working? 任何人都可以指出为什么这不起作用? I take out the filter and the search runs perfectly. 我拿出过滤器,搜索运行完美。 I add the filter and getInputData chokes on the search. 我在搜索中添加了filter和getInputData chokes。

Thank you for your time! 感谢您的时间!

For sure, if this is "transaction" search, the filters should be "join". 当然,如果这是“交易”搜索,过滤器应该是“加入”。 Try to change the first filter field from "itemid" to "name". 尝试将第一个过滤字段从“itemid”更改为“name”。 Like this: 像这样:

var mySearch = search.load({ id: 'customsearch_so_itemclassid' });
mySearch.filters.push(search.createFilter({ name: 'name', join: 'item', operator: 'IS', values: [itemName] }));
mySearch.filters.push(search.createFilter({ name: 'class', join: 'item', operator: 'ISNOT', values: [itemClass] }));

I know that it sounds stupid, but give it a try. 我知道这听起来很愚蠢,但试一试。
And one different approach - You can use filterExpression, instead of filters. 一种不同的方法 - 您可以使用filterExpression而不是过滤器。 Like this: 像这样:

var mySearch = search.load({ id: 'customsearch_so_itemclassid' });
var myAdditionalFilters = [ 'and', ['item.name', 'is', [itemName] ],
                            'and', ['item.class', 'isnot', [itemClass] ]
                          ];
var myNewFilterExpression = mySearch.filterExpression.concat(myAdditionalFilters);
mySearch.filterExpression = myNewFilterExpression;

As it turned out, I was confused on how the saved search gathered information and applying the filter the way I was created basically an endless loop. 事实证明,我对于保存的搜索如何收集信息并按照我创建的方式应用过滤器基本上是无限循环感到困惑。 The idea is to search the Sales Orders after a User change an Item's class and update the Sales Order's line items to the new class should the Line Item be the same Item Name and a different Class. 我们的想法是在用户更改项目类后搜索销售订单,并在行项目为相同项目名称和不同类别时将销售订单的行项目更新为新类别。 So the filter wound up looking like this instead: 所以过滤器看起来像这样:

 var mySearch = search.load({ id: 'customsearch_so_itemclassid' });
 var filters = mySearch.filters;
 filters.push(search.createFilter({ name: 'name', join: 'item', operator: 'IS', values: [itemName] }));
 filters.push(search.createFilter({ name: 'class', operator: 'NONEOF', values: [itemClass] }));
 mySearch.filters = filters;

With that, the search worked. 有了这个,搜索工作。 I now have a new problem described in one of my replies below. 我现在在下面的一个回复中描述了一个新问题。 The searchResults in the map function look like this: map函数中的searchResults如下所示:

{"recordType":null,"id":"1","values":{"GROUP(tranid)":"289092"}}

I can't seem to get the value from that key value pair. 我似乎无法从该键值对中获取值。 I use "entity" and it's undefined. 我使用“实体”,它是未定义的。 I use "tranid" and it's undefined. 我使用“tranid”,它是未定义的。 I've tried several different combinations and I can't get to that value. 我尝试了几种不同的组合,但我无法达到这个价值。

Since I answered this question with the above filters, this is a new question indeed. 由于我用上述过滤器回答了这个问题,这确实是一个新问题。 But if someone could throw some light on this, I would be extremely grateful. 但如果有人能对此有所了解,我将非常感激。

It is better to ask your second question separate. 最好分开问你的第二个问题。 Anyway, in your case, because of the grouping function in the search, 'tranid' in map stage should be accessed like this: 无论如何,在你的情况下,由于搜索中的分组功能,地图阶段的'tranid'应该像这样访问:

        var searchResult = JSON.parse(context.value);
        var salesOrderId = searchResult.id;
        var tranId = searchResult.values['GROUP(tranid)'];

I'm not sure if this is your problem, but I have found that in some cases where you load an existing search you cannot "push" directly to the search filters object, and need to assign it to a temporary variable first. 我不确定这是否是您的问题,但我发现在某些情况下,您加载现有搜索时无法直接“推送”到搜索过滤器对象,需要先将其分配给临时变量。 Maybe something weird on the Rhino backend. 也许在Rhino后端有些奇怪。

var mySearch = search.load({ id: 'customsearch_so_itemclassid' });
var filters = mySearch.filters;
filters.push(search.createFilter({ name: 'itemid', operator: 'IS', values: [itemName] }));
filters.push(search.createFilter({ name: 'class', operator: 'ISNOT', values: [itemClass] }));
mySearch.filters = filters;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM