您如何使用 TransactionSearch 进行搜索?

您如何找到具有供应商付款内部 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);




        }

搜索结果返回成功,但recordlist 中没有记录,searchrowlist 中没有搜索。


莫回无
浏览 114回答 1
1回答

LEATH

想象一下TransactionSearchAdvanced()UI 中保存的搜索。您需要指定要使用的条件以及要返回的列。在运行搜索之前,添加以下代码以指定要返回的列。您可能还想为 mainLine 添加一个条件,否则true每个事务行将得到一个结果,而不是每个事务一个结果。tranSearch.columns = new TransactionSearchRow(){&nbsp; &nbsp; basic = new TransactionSearchRowBasic()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; tranId = new[] {new SearchColumnStringField()}&nbsp; &nbsp; }};var result = ns.search(tranSearch);if (result.status.isSuccess){&nbsp; &nbsp; foreach (var rowList in result.searchRowList)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (rowList is TransactionSearchRow row)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var tranId = row.basic.tranId[0].searchValue;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var total = row.basic.total[0].searchValue;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($"{tranId} - {total}");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}最简单的方法:因为你有内部 ID,你可以TransactionSearchBasic()像这样获取整个记录:var search = new TransactionSearchBasic(){&nbsp; &nbsp; type = new SearchEnumMultiSelectField()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; @operator = SearchEnumMultiSelectFieldOperator.anyOf,&nbsp; &nbsp; &nbsp; &nbsp; searchValue = new[] { "_vendorPayment" },&nbsp; &nbsp; &nbsp; &nbsp; operatorSpecified = true,&nbsp; &nbsp; },&nbsp; &nbsp; internalId = new SearchMultiSelectField()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; @operator = SearchMultiSelectFieldOperator.anyOf,&nbsp; &nbsp; &nbsp; &nbsp; searchValue = new[] { new RecordRef { internalId = "723212" } },&nbsp; &nbsp; &nbsp; &nbsp; operatorSpecified = true&nbsp; &nbsp; }};var results = ns.search(search);foreach (var result in results.recordList){&nbsp; &nbsp; if (result is VendorPayment vendorPayment)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine(vendorPayment.tranId);&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP