如何使用多个术语创建 NetSuite SuiteTalk 搜索? [英] How to create NetSuite SuiteTalk search with multiple terms?

查看:84
本文介绍了如何使用多个术语创建 NetSuite SuiteTalk 搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个 SuiteTalk (NetSuite web api) 搜索查询,指定多个搜索词来指示逻辑 OR 运算符?

How does one create a SuiteTalk (NetSuite web api) search query specifying multiple search terms indicating a logical OR operator?

例如,我想检索 create OR 上次修改日期 在特定范围内的 TimeBill 记录.这是我的代码,适用于单个搜索词.只需添加另一个搜索词即可创建逻辑 AND 运算.

For example, I want to retrieve TimeBill records whose create OR last modified dates are within a particular range. Here's my code that works great for a single search term. Simply adding another search term appears to create a logical AND operation.

    /// <summary>
    /// Return the list of time bills whose last modified date is within 
    /// the indicated date range.
    /// </summary>
    /// <param name="from">Required from date</param>
    /// <param name="to">Optional to date</param>
    /// <returns>List of time bills</returns>
    public IEnumerable<TimeBill> GetTimeBills(DateTime from, DateTime to)
    {
        _log.Debug(String.Format("Enter TimeBill(DateTime from='{0}', DateTime to='{1}')", from, to));

        // Build search criteria.
        TimeBillSearch search = new TimeBillSearch();
        TimeBillSearchBasic searchBasic = new TimeBillSearchBasic();
        SearchDateField searchDateField = new SearchDateField();
        searchDateField.@operator = SearchDateFieldOperator.within;
        searchDateField.operatorSpecified = true;
        searchDateField.searchValue = from;
        searchDateField.searchValueSpecified = true;
        searchDateField.searchValue2 = to;
        searchDateField.searchValue2Specified = true;
        searchBasic.dateCreated = searchDateField;            
        search.basic = searchBasic;

        return this.Get<TimeBill>(search);
    }  

    /// <summary>
    /// Perform a paged search and convert the returned record to the indicated type.
    /// </summary>
    private IEnumerable<T> Get<T>(SearchRecord searchRecord)
    {
        _log.Debug("Enter Get<T>(SearchRecord searchRecord)");

        // This is returned.
        List<T> list = new List<T>();

        // The suitetalk service return this.
        SearchResult result = null;

        using (ISuiteTalkService service = SuiteTalkFactory.Get<SuiteTalkService>())
        {
            do
            {
                // .search returns the first page of data.
                if (result == null)
                {
                    result = service.search(searchRecord);
                }
                else // .searchMore returns the next page(s) of data.
                {
                    result = service.searchMoreWithId(result.searchId, result.pageIndex + 1);
                }

                if (result.status.isSuccess)
                {
                    foreach (Record record in result.recordList)
                    {
                        if (record is T)
                        {
                            list.Add((T)Convert.ChangeType(record, typeof(T)));
                        }
                    }
                }
            }
            while (result.pageIndex < result.totalPages);
        }
        return list;
    }

推荐答案

根据 NetSuite 用户社区(论坛),我认为目前这不可能(至少它没有出现在 SuiteTalk/Web 服务的 WSDL 中): https://usergroup.netsuite.com/users/showthread.php?t=29818

Per the NetSuite User Community (forum), I do not believe this is currently possible (at least it does not appear in the WSDL for SuiteTalk/Web Services): https://usergroup.netsuite.com/users/showthread.php?t=29818

但是,您可以通过使用 nlobjSearchFilter 方法 setLeftParens()、setRightParens() 和 setOr()(如您所推测的,当存在多个过滤器时,逻辑AND"是默认行为).

However, you can dynamically create a complex Saved Search (using SuiteScript in a Suitelet) that includes AND/OR and parentheses by using the nlobjSearchFilter methods setLeftParens(), setRightParens(), and setOr() (as you surmised, a logical "AND" is the default behavior when multiple filters are present).

动态创建的已保存搜索(我知道这里的术语令人困惑)也可以保存和加载以供以后重用.因此,您可以通过让您的 Web 服务代码调用保存的搜索并检索结果来利用 NetSuite 服务器上动态创建的保存的搜索,但仍然使所有内容都是动态的(没有硬编码的搜索过滤器/值).

A dynamically created Saved Search (confusing terminology here, I know) can also be saved and loaded for later reuse. You could therefore potentially take advantage of dynamically created Saved Searches on the NetSuite server by having your Web Services code invoke a Saved Search and retrieve the results, yet still have everything be dynamic (no hardcoded search filters/values).

正如在论坛中提到的,您也可以自己执行多个搜索并将结果拼接在一起(在您的 SuiteTalk C#/Java 等代码中).

As mentioned on the Forum, you could also potentially execute multiple searches and stitch the results together yourself (in your SuiteTalk C#/Java etc. code).

这篇关于如何使用多个术语创建 NetSuite SuiteTalk 搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆