如何使用TransactionSearch进行搜索?

时间:2019-04-19 21:31:36

标签: c# netsuite

您如何找到带有供应商付款内部ID的供应商付款(交易)? 我很难理解交易搜索的工作方式。

下面是我的代码:它返回成功但没有结果

using (var serviceClient = new ServiceClient(token))
        {
            var tranSearch = new TransactionSearchAdvanced();

            var recordRefs = new List<RecordRef>();
            recordRefs.Add(new RecordRef()
            {
                internalId = @"723212",
                type = RecordType.vendorPayment,
                typeSpecified = true
            });

            var types = new List<string>();
            types.Add(@"_vendorPayment");
            tranSearch.criteria = new TransactionSearch()
            {
                basic = new TransactionSearchBasic()
                {
                    internalId = new SearchMultiSelectField()
                    {
                        @operator = SearchMultiSelectFieldOperator.anyOf,
                        operatorSpecified = true,
                        searchValue = recordRefs.ToArray()
                    },
                    type = new SearchEnumMultiSelectField()
                    {
                        @operator = SearchEnumMultiSelectFieldOperator.anyOf,
                        operatorSpecified = true,
                        searchValue = types.ToArray()
                    }                        
                }                    

            };                

            var result = serviceClient.search(tranSearch);



        }

搜索结果返回成功,但是记录列表中没有记录或搜索行列表中没有搜索。

1 个答案:

答案 0 :(得分:1)

TransactionSearchAdvanced()视为用户界面中的已保存搜索。您需要指定使用条件AND要返回的列。在运行搜索之前,请添加以下代码以指定要返回的列。您可能还需要为mainLine添加一个条件true,否则您将在每个交易行获得一个结果,而不是每个交易获得一个结果。

tranSearch.columns = new TransactionSearchRow()
{
    basic = new TransactionSearchRowBasic()
    {
        tranId = new[] {new SearchColumnStringField()}
    }
};

var result = ns.search(tranSearch);

if (result.status.isSuccess)
{
    foreach (var rowList in result.searchRowList)
    {
        if (rowList is TransactionSearchRow row)
        {
            var tranId = row.basic.tranId[0].searchValue;
            var total = row.basic.total[0].searchValue;
            Console.WriteLine($"{tranId} - {total}");
        }
    }
}

最简便的方法:由于您具有内部ID,因此可以使用TransactionSearchBasic()来获取整个记录,如下所示:

var search = new TransactionSearchBasic()
{
    type = new SearchEnumMultiSelectField()
    {
        @operator = SearchEnumMultiSelectFieldOperator.anyOf,
        searchValue = new[] { "_vendorPayment" },
        operatorSpecified = true,
    },
    internalId = new SearchMultiSelectField()
    {
        @operator = SearchMultiSelectFieldOperator.anyOf,
        searchValue = new[] { new RecordRef { internalId = "723212" } },
        operatorSpecified = true
    }
};

var results = ns.search(search);

foreach (var result in results.recordList)
{
    if (result is VendorPayment vendorPayment)
    {
        Console.WriteLine(vendorPayment.tranId);
    }
}