我只使用NetSuite和SuiteTalk不到一年。我找到了利用已保存搜索的基本搜索和高级搜索的示例,但我很难找到如何使用条件和结果集中的选定列从头开始执行高级搜索的示例。所以我要求举例。
答案 0 :(得分:1)
我查看了可从NetSuite下载的NSClientERP项目中提供的示例。这是一个简化的例子。
service.searchPreferences = new SearchPreferences();
service.searchPreferences.bodyFieldsOnly = true;
service.searchPreferences.returnSearchColumns = true;
TransactionSearchAdvanced customSearch = new TransactionSearchAdvanced()
{
columns = new TransactionSearchRow()
{
basic = new TransactionSearchRowBasic()
{
dateCreated = new SearchColumnDateField[] { new SearchColumnDateField() }
, tranDate = new SearchColumnDateField[] { new SearchColumnDateField() }
, type = new SearchColumnEnumSelectField[] { new SearchColumnEnumSelectField() }
, tranId = new SearchColumnStringField[] { new SearchColumnStringField() }
, internalId = new SearchColumnSelectField[] { new SearchColumnSelectField() }
, entity = new SearchColumnSelectField[] { new SearchColumnSelectField() }
, item = new SearchColumnSelectField[] { new SearchColumnSelectField() }
, lastModifiedDate = new SearchColumnDateField[] { new SearchColumnDateField() }
}
, itemJoin = new ItemSearchRowBasic()
{
itemId = new SearchColumnStringField[] { new SearchColumnStringField() }
}
}
,
criteria = new TransactionSearch()
{
basic = new TransactionSearchBasic()
{
type = new SearchEnumMultiSelectField()
{
@operator = SearchEnumMultiSelectFieldOperator.anyOf
, operatorSpecified = true
, searchValue = new string[] {
"_salesOrder"
}
}
, lastModifiedDate = new SearchDateField()
{
@operator = SearchDateFieldOperator.onOrAfter
, operatorSpecified = true
, searchValue = DateTime.Now.AddDays(-3)
, searchValueSpecified = true
}
}
}
};
Console.WriteLine("Querying NetSuite");
SearchResult searchResult = service.search(customSearch);
Console.WriteLine("Query Results: " + searchResult.totalRecords.ToString());
int total = searchResult.totalRecords;
int updated = 0;
bool searchMore = false;
Console.WriteLine("\nThe search() operation for transaction was run successfully.");
Console.WriteLine("\n Total Records = " + searchResult.totalRecords);
Console.WriteLine(" Total Pages = " + searchResult.totalPages);
Console.WriteLine(" Page Size = " + searchResult.pageSize);
Console.WriteLine(" Current Page Index = " + searchResult.pageIndex);
Console.WriteLine("\n\nHit Enter to list results");
Console.ReadLine();
SearchRow[] records = searchResult.searchRowList;
if (records != null)
{
for (int i = 0, j = (searchResult.pageIndex - 1) * searchResult.pageSize; i < records.Length; i++, j++)
{
TransactionSearchRow transactionRow = (TransactionSearchRow) records[i];
TransactionSearchRowBasic transactionRowBasic = transactionRow.basic;
ItemSearchRowBasic itemRowBasic = transactionRow.itemJoin;
Console.WriteLine(
"\n Transaction Return Columns Row[" + j + "]: " +
"\n internalId=" + transactionRowBasic.internalId[0].searchValue.internalId +
"\n tranId=" + transactionRowBasic.tranId[0].searchValue +
"\n type=" + transactionRowBasic.type[0].searchValue +
(transactionRowBasic.entity == null ? "" : ("\n customer internalID=" + transactionRowBasic.entity[0].searchValue.internalId)) +
(transactionRowBasic.item == null ? "" : ("\n item=" + transactionRowBasic.item[0].searchValue.internalId)) +
(itemRowBasic == null ? "" : ("\n item.name=" + itemRowBasic.itemId[0].searchValue)) +
(transactionRowBasic.dateCreated == null ? "" : ("\n createdDate=" + transactionRowBasic.dateCreated[0].searchValue.ToString()) +
(transactionRowBasic.tranDate == null ? "" : ("\n tranDate=" + transactionRowBasic.tranDate[0].searchValue.ToString())) +
(transactionRowBasic.lastModifiedDate == null ? "" : ("\n lastModifiedDate=" + transactionRowBasic.lastModifiedDate[0].searchValue.ToString()))));
}
}
在执行高级搜索之前设置搜索首选项非常重要。没有将returnSearchFields设置为true,我没有得到任何结果。此外,您必须提供标准和列。在NSClientERP示例中,以TransactionSearchAdvanced开头的每个对象都被实例化,配置并链接到单独代码行中的子对象。我发现这很难遵循。我使用一行代码来实例化整个搜索对象。
需要注意的另一件事是itemJoin,它将Items表连接到销售订单行项目。还有其他可用的联接,例如billingTransactionJoin。利用这些联接,您可以访问相关联的表格,以便在项目发布时获取项目的显示名称,库存信息或跟踪号码。
除了填充数据集并在事后排序之外,我一直无法找到对结果进行排序的方法。如果有人有更好的方法,请告诉我。
答案 1 :(得分:1)
这是一个实际上正确进行分页的示例。
service.searchPreferences = new SearchPreferences();
service.searchPreferences.bodyFieldsOnly = true;
service.searchPreferences.returnSearchColumns = true;
TransactionSearchAdvanced customSearch = new TransactionSearchAdvanced()
{
columns = new TransactionSearchRow()
{
basic = new TransactionSearchRowBasic()
{
dateCreated = new SearchColumnDateField[] { new SearchColumnDateField() }
,
tranDate = new SearchColumnDateField[] { new SearchColumnDateField() }
,
type = new SearchColumnEnumSelectField[] { new SearchColumnEnumSelectField() }
,
tranId = new SearchColumnStringField[] { new SearchColumnStringField() }
,
internalId = new SearchColumnSelectField[] { new SearchColumnSelectField() }
,
entity = new SearchColumnSelectField[] { new SearchColumnSelectField() }
,
item = new SearchColumnSelectField[] { new SearchColumnSelectField() }
,
lastModifiedDate = new SearchColumnDateField[] { new SearchColumnDateField() }
}
,
itemJoin = new ItemSearchRowBasic()
{
itemId = new SearchColumnStringField[] { new SearchColumnStringField() }
}
}
,
criteria = new TransactionSearch()
{
basic = new TransactionSearchBasic()
{
type = new SearchEnumMultiSelectField()
{
@operator = SearchEnumMultiSelectFieldOperator.anyOf
,
operatorSpecified = true
,
searchValue = new string[] {
"_salesOrder"
}
}
,
lastModifiedDate = new SearchDateField()
{
@operator = SearchDateFieldOperator.onOrAfter
,
operatorSpecified = true
,
searchValue = DateTime.Now.AddDays(-15)
,
searchValueSpecified = true
}
}
}
};
Console.WriteLine("Querying NetSuite");
SearchResult res = service.search(customSearch);
Console.WriteLine("\nThe advanced search completed.");
Console.WriteLine("\n Total Records = " + res.totalRecords);
Console.WriteLine(" Total Pages = " + res.totalPages);
Console.WriteLine(" Page Size = " + res.pageSize);
Console.WriteLine(" Current Page Index = " + res.pageIndex);
Console.WriteLine("\n\nHit Enter to list results");
Console.ReadLine();
while (res.searchRowList.Length > 0)
{
Console.WriteLine($"\n\nProcessing page: {res.pageIndex}");
Console.WriteLine($"Result count: {res.searchRowList.Length}");
Console.WriteLine($"\nHit enter to list page {res.pageIndex} results");
Console.ReadLine();
foreach (TransactionSearchRow transactionRow in res.searchRowList)
{
TransactionSearchRowBasic transactionRowBasic = transactionRow.basic;
ItemSearchRowBasic itemRowBasic = transactionRow.itemJoin;
Console.WriteLine(
"\n tranId=" + transactionRowBasic.tranId[0].searchValue +
(itemRowBasic == null ? "" : ("\n item.name=" + itemRowBasic.itemId[0].searchValue))
);
}
Console.WriteLine("\nQuerying NetSuite again...");
res = service.searchMore(++res.pageIndex);
}
service.logout();
Console.WriteLine("\n\nHit Enter to close this window.");
Console.ReadLine();
答案 2 :(得分:0)
一年后,我回到了这段代码。我正在编码另一个高级搜索,并认为也许没有必要在数组定义中添加空白元素。那是个错误。绝对必要!如果您省略这些选项,则搜索有效,但是对SearchResult.basic和SearchResult.ItemJoin仅返回null。
TransactionSearchAdvanced advanced = new TransactionSearchAdvanced()
{
columns = new TransactionSearchRow()
{
basic = new TransactionSearchRowBasic()
{
// new SearchColumnSelectField() is required!!!!!!
internalId = new SearchColumnSelectField[] { new SearchColumnSelectField() }
}
,
itemJoin = new ItemSearchRowBasic()
{
// new SearchColumnSelectField() is required!!!!!!
externalId = new SearchColumnSelectField[] { new SearchColumnSelectField() }
}
}
}