SuiteTalk Advanced Search Examples
NickName:Kevin M Ask DateTime:2017-11-28T23:11:49

SuiteTalk Advanced Search Examples

I've only worked with NetSuite and SuiteTalk for less than one year. I've found examples of basic searches and advanced searches that leverage saved searches, but I had a hard time finding examples of how to perform an advanced search from scratch with criteria and selected columns in the result set. So I'm asking for examples.

Copyright Notice:Content Author:「Kevin M」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47534845/suitetalk-advanced-search-examples

Answers
Kevin M 2017-11-28T18:22:50

Here's an example that actually does the paging correctly.\n\nservice.searchPreferences = new SearchPreferences();\nservice.searchPreferences.bodyFieldsOnly = true;\nservice.searchPreferences.returnSearchColumns = true;\n\nTransactionSearchAdvanced customSearch = new TransactionSearchAdvanced()\n{\n columns = new TransactionSearchRow()\n {\n basic = new TransactionSearchRowBasic()\n {\n dateCreated = new SearchColumnDateField[] { new SearchColumnDateField() }\n ,\n tranDate = new SearchColumnDateField[] { new SearchColumnDateField() }\n ,\n type = new SearchColumnEnumSelectField[] { new SearchColumnEnumSelectField() }\n ,\n tranId = new SearchColumnStringField[] { new SearchColumnStringField() }\n ,\n internalId = new SearchColumnSelectField[] { new SearchColumnSelectField() }\n ,\n entity = new SearchColumnSelectField[] { new SearchColumnSelectField() }\n ,\n item = new SearchColumnSelectField[] { new SearchColumnSelectField() }\n ,\n lastModifiedDate = new SearchColumnDateField[] { new SearchColumnDateField() }\n }\n ,\n itemJoin = new ItemSearchRowBasic()\n {\n itemId = new SearchColumnStringField[] { new SearchColumnStringField() }\n }\n }\n ,\n criteria = new TransactionSearch()\n {\n basic = new TransactionSearchBasic()\n {\n type = new SearchEnumMultiSelectField()\n {\n @operator = SearchEnumMultiSelectFieldOperator.anyOf\n ,\n operatorSpecified = true\n ,\n searchValue = new string[] {\n \"_salesOrder\"\n }\n }\n ,\n lastModifiedDate = new SearchDateField()\n {\n @operator = SearchDateFieldOperator.onOrAfter\n ,\n operatorSpecified = true\n ,\n searchValue = DateTime.Now.AddDays(-15)\n ,\n searchValueSpecified = true\n }\n }\n }\n};\n\nConsole.WriteLine(\"Querying NetSuite\");\n\nSearchResult res = service.search(customSearch);\n\nConsole.WriteLine(\"\\nThe advanced search completed.\");\nConsole.WriteLine(\"\\n Total Records = \" + res.totalRecords);\nConsole.WriteLine(\" Total Pages = \" + res.totalPages);\nConsole.WriteLine(\" Page Size = \" + res.pageSize);\nConsole.WriteLine(\" Current Page Index = \" + res.pageIndex);\n\nConsole.WriteLine(\"\\n\\nHit Enter to list results\");\nConsole.ReadLine();\n\nwhile (res.searchRowList.Length > 0)\n{\n Console.WriteLine($\"\\n\\nProcessing page: {res.pageIndex}\");\n Console.WriteLine($\"Result count: {res.searchRowList.Length}\");\n\n Console.WriteLine($\"\\nHit enter to list page {res.pageIndex} results\");\n Console.ReadLine();\n\n\n foreach (TransactionSearchRow transactionRow in res.searchRowList)\n {\n TransactionSearchRowBasic transactionRowBasic = transactionRow.basic;\n ItemSearchRowBasic itemRowBasic = transactionRow.itemJoin;\n Console.WriteLine(\n \"\\n tranId=\" + transactionRowBasic.tranId[0].searchValue +\n (itemRowBasic == null ? \"\" : (\"\\n item.name=\" + itemRowBasic.itemId[0].searchValue)) \n );\n }\n\n Console.WriteLine(\"\\nQuerying NetSuite again...\");\n res = service.searchMore(++res.pageIndex);\n}\n\nservice.logout();\nConsole.WriteLine(\"\\n\\nHit Enter to close this window.\");\nConsole.ReadLine();\n",


Kevin M 2017-11-28T15:28:26

I reviewed examples provided in the NSClientERP project downloadable from NetSuite. Here is a simplified example. \n\n service.searchPreferences = new SearchPreferences();\n service.searchPreferences.bodyFieldsOnly = true;\n service.searchPreferences.returnSearchColumns = true;\n\n TransactionSearchAdvanced customSearch = new TransactionSearchAdvanced()\n {\n columns = new TransactionSearchRow()\n {\n basic = new TransactionSearchRowBasic()\n {\n dateCreated = new SearchColumnDateField[] { new SearchColumnDateField() }\n , tranDate = new SearchColumnDateField[] { new SearchColumnDateField() }\n , type = new SearchColumnEnumSelectField[] { new SearchColumnEnumSelectField() }\n , tranId = new SearchColumnStringField[] { new SearchColumnStringField() }\n , internalId = new SearchColumnSelectField[] { new SearchColumnSelectField() }\n , entity = new SearchColumnSelectField[] { new SearchColumnSelectField() }\n , item = new SearchColumnSelectField[] { new SearchColumnSelectField() }\n , lastModifiedDate = new SearchColumnDateField[] { new SearchColumnDateField() }\n }\n , itemJoin = new ItemSearchRowBasic()\n {\n itemId = new SearchColumnStringField[] { new SearchColumnStringField() }\n }\n }\n ,\n criteria = new TransactionSearch()\n {\n basic = new TransactionSearchBasic()\n {\n type = new SearchEnumMultiSelectField()\n {\n @operator = SearchEnumMultiSelectFieldOperator.anyOf\n , operatorSpecified = true\n , searchValue = new string[] {\n \"_salesOrder\"\n }\n }\n , lastModifiedDate = new SearchDateField()\n {\n @operator = SearchDateFieldOperator.onOrAfter\n , operatorSpecified = true\n , searchValue = DateTime.Now.AddDays(-3)\n , searchValueSpecified = true\n }\n }\n }\n };\n\n Console.WriteLine(\"Querying NetSuite\");\n\n SearchResult searchResult = service.search(customSearch);\n\n Console.WriteLine(\"Query Results: \" + searchResult.totalRecords.ToString());\n int total = searchResult.totalRecords;\n int updated = 0;\n bool searchMore = false;\n\n\n Console.WriteLine(\"\\nThe search() operation for transaction was run successfully.\");\n Console.WriteLine(\"\\n Total Records = \" + searchResult.totalRecords);\n Console.WriteLine(\" Total Pages = \" + searchResult.totalPages);\n Console.WriteLine(\" Page Size = \" + searchResult.pageSize);\n Console.WriteLine(\" Current Page Index = \" + searchResult.pageIndex);\n\n Console.WriteLine(\"\\n\\nHit Enter to list results\");\n Console.ReadLine();\n\n SearchRow[] records = searchResult.searchRowList;\n\n if (records != null)\n {\n for (int i = 0, j = (searchResult.pageIndex - 1) * searchResult.pageSize; i < records.Length; i++, j++)\n {\n TransactionSearchRow transactionRow = (TransactionSearchRow) records[i];\n TransactionSearchRowBasic transactionRowBasic = transactionRow.basic;\n ItemSearchRowBasic itemRowBasic = transactionRow.itemJoin;\n Console.WriteLine(\n \"\\n Transaction Return Columns Row[\" + j + \"]: \" +\n \"\\n internalId=\" + transactionRowBasic.internalId[0].searchValue.internalId +\n \"\\n tranId=\" + transactionRowBasic.tranId[0].searchValue +\n \"\\n type=\" + transactionRowBasic.type[0].searchValue +\n (transactionRowBasic.entity == null ? \"\" : (\"\\n customer internalID=\" + transactionRowBasic.entity[0].searchValue.internalId)) +\n (transactionRowBasic.item == null ? \"\" : (\"\\n item=\" + transactionRowBasic.item[0].searchValue.internalId)) +\n (itemRowBasic == null ? \"\" : (\"\\n item.name=\" + itemRowBasic.itemId[0].searchValue)) +\n (transactionRowBasic.dateCreated == null ? \"\" : (\"\\n createdDate=\" + transactionRowBasic.dateCreated[0].searchValue.ToString()) +\n (transactionRowBasic.tranDate == null ? \"\" : (\"\\n tranDate=\" + transactionRowBasic.tranDate[0].searchValue.ToString())) +\n (transactionRowBasic.lastModifiedDate == null ? \"\" : (\"\\n lastModifiedDate=\" + transactionRowBasic.lastModifiedDate[0].searchValue.ToString()))));\n }\n }\n\n\nIt is important to set your search preferences prior to performing your advanced search. Without setting returnSearchFields to true, I got no results. Also, you must supply both criteria and columns. In the NSClientERP example, each object starting with the TransactionSearchAdvanced was instantiated, configured and linked to child objects in separate lines of code. I found this very hard to follow. I'm using one line of code that instantiates the entire search object.\n\nAnother thing to note is the itemJoin, which joins the Items table to a sales order line item. There are other joins available to you, such as billingTransactionJoin. Leveraging those joins, you can reach into associated tables to get things like the item's display name, inventory information, or tracking numbers when an item ships.\n\nI have been unable to find a way to sort the results, other than filling a dataset and sorting after the fact. If anyone has a better way, please let me know. ",


More about “SuiteTalk Advanced Search Examples” related questions

SuiteTalk Advanced Search Examples

I've only worked with NetSuite and SuiteTalk for less than one year. I've found examples of basic searches and advanced searches that leverage saved searches, but I had a hard time finding examples...

Show Detail

Dynamic Search using Suitetalk

I am trying to create a C# application (Using suitetalk) that would allow us to search through Netsuite records. The record type will be specified dynamically. Please can you help? I have checked ...

Show Detail

netsuite join on suitetalk searches

If I read correctly, in SuiteScript you can do a search that brings back a joint of two record types if they are parent child types of records even if they are custom recordTypes (such as for example

Show Detail

NetSuite SuiteTalk TransactionSearchAdvanced: recordList equals null

I have a small C# console application who's sole purpose is to receive records from a "Saved Search" in NetSuite(via SuiteTalk). I've been able to successfully connect and receive records from NetS...

Show Detail

SuiteTalk and timezone inconsistency

I do a search via SuiteTalk and get a single record with lastModifiedDate: &lt;listRel:lastModifiedDate&gt;2014-12-12T11:12:24.000-08:00&lt;/listRel:lastModifiedDate&gt; I updated this record at ...

Show Detail

How to retrieve Currency Revaluation transactions using SuiteTalk web service

One type of transaction in NetSuite is "Currency Revaluation" and there are examples of such transactions (e.g. see those with InternalIDs 3335, 3346 and 3347 in the NetSuite testdrive sample data,

Show Detail

NetSuite SOAP API (SuiteTalk) to dump General Ledger

Can anyone give me advice on how to read the general ledger using SuiteTalk, the SOAP API from NetSuite? For example, if you look at an account or a transaction on the NetSuite UI, there is an opt...

Show Detail

How do I run a saved search for a search type of "saved search" in Netsuite SuiteTalk

I have a saved search in Netsuite UI to search the saved searches. I need to execute this saved search and get the results in suiteTalk. I have called GetSavedSearchResult savedSearchResult = s...

Show Detail

How to create NetSuite SuiteTalk search with multiple terms?

How does one create a SuiteTalk (NetSuite web api) search query specifying multiple search terms indicating a logical OR operator? For example, I want to retrieve TimeBill records whose create OR ...

Show Detail

In NetSuite using SuiteTalk, Is it possible to create a CSV file from saved search

Backgorund: I am a newbie in the NetSuite world. We are trying to integrate NetSuite with our ERP and I am doing some preliminary research to find out what would be the best option moving ahead. The

Show Detail