如何使用多个术语创建NetSuite SuiteTalk搜索?

时间:2012-06-05 15:32:55

标签: netsuite

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

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

    /// <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;
    }

1 个答案:

答案 0 :(得分:0)

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

但是,您可以使用nlobjSearchFilter方法setLeftParens(),setRightParens()和setOr()动态创建包含AND / OR和括号的复杂保存搜索(使用Suitelet中的SuiteScript)(如您所推测的,逻辑“AND”是存在多个过滤器时的默认行为。)

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

正如论坛上所提到的,您还可以执行多次搜索并将结果拼接在一起(在您的SuiteTalk C#/ Java等代码中)。