2

I am attempting to get the items and some of the related information from a Purchase Order with SuiteTalk. I am able to get the desired Purchase Orders with TransactionSearch using the following in Scala:

val transactionSearch = new TransactionSearch  
val search = new TransactionSearchBasic  
...
search.setLastModifiedDate(searchLastModified) //Gets POs modified in the last 10 minutes
transactionSearch.setBasic(search)  

val result = port.search(transactionSearch)  

I am able to cast each result to a record as an instance of the PurchaseOrder class.

if (result.getStatus().isIsSuccess()) {
  println("Transactions: " + result.getTotalRecords)
  for (i <- 0 until result.getTotalRecords) {
    try {
      val record = result.getRecordList.getRecord.get(i).asInstanceOf[PurchaseOrder]
      record.get<...>
    }
    catch {...}  
  }
}

From here I am able to use the getters to access the individual fields, except for the ItemList.

I can see in the NetSuite web interface that there are items attached to the Purchase Orders. However using getItemList on the result record is always returning a null response.

Any thoughts?

the3rdNotch
  • 637
  • 2
  • 8
  • 18

1 Answers1

3

I think you have not used search preferences and that is why you are not able to fetch purchase order line items. You will have to use following search preferences in your code -

        SearchPreferences prefrence = new SearchPreferences();
        prefrence.bodyFieldsOnly = false;

        _service.searchPreferences = prefrence;

Following is working example using above preferences -

    private void SearchPurchaseOrderByID(string strPurchaseOrderId)
    {
        TransactionSearch tranSearch = new TransactionSearch();
        TransactionSearchBasic tranSearchBasic = new TransactionSearchBasic();


        RecordRef poRef = new RecordRef();
        poRef.internalId = strPurchaseOrderId;
        poRef.type = RecordType.purchaseOrder;
        poRef.typeSpecified = true;

        RecordRef[] poRefs = new RecordRef[1];
        poRefs[0] = poRef;

        SearchMultiSelectField poID = new SearchMultiSelectField();
        poID.searchValue = poRefs;
        poID.@operator = SearchMultiSelectFieldOperator.anyOf;
        poID.operatorSpecified = true;

        tranSearchBasic.internalId = poID;
        tranSearch.basic = tranSearchBasic;

        InitService();
        SearchResult results = _service.search(tranSearch);
        if (results.status.isSuccess && results.status.isSuccessSpecified)
        {
            Record[] poRecords = results.recordList;
            PurchaseOrder purchaseOrder = (PurchaseOrder)poRecords[0];
            PurchaseOrderItemList poItemList = purchaseOrder.itemList;
            PurchaseOrderItem[] poItems = poItemList.item;
            if (poItems != null && poItems.Length > 0)
            {
                for (var i = 0; i < poItems.Length; i++)
                {
                    Console.WriteLine("Item Line On PO = " + poItems[i].line);                        
                    Console.WriteLine("Item Quantity = " + poItems[i].quantity);
                    Console.WriteLine("Item Descrition = " + poItems[i].description);
                }
            }
        }
    }
  • Thank you for the suggestion. My results are returning purchase orders, but I am unable to apply the searchPreferences to my service, and am still getting `null` for the itemList. What I have for setting up the service, maybe I'm doing it the wrong way: `val service = new NetSuiteService();` `val resolver = new HeaderHandlerResolver;` `service.setHandlerResolver(resolver);` `val port = service.getNetSuitePort;` `val preferences = new SearchPreferences;` `preferences.setBodyFieldsOnly(false);` I do not have a `port.searchPreferences` option for the preferences. – the3rdNotch Feb 25 '16 at 17:00
  • 1
    You have to add search preferences to NetSuite service object like - NetSuiteService _service = new NetSuiteService(); SearchPreferences prefrence = new SearchPreferences(); prefrence.bodyFieldsOnly = false; _service.searchPreferences = prefrence; – NetSuite Expert Feb 26 '16 at 01:22
  • 1
    It depends on how you compiled the WSDL into Java. If you used Axis 1.4 (as in NetSuite's demo), then `port` (returned by `getNetSuitePort`) will be of type NetSuiteBindingStub. Then do `port.setHeader("urn:messages_2015_2.platform.webservices.netsuite.com", "searchPreferences", prefrence);`. – Klitos Kyriacou Feb 26 '16 at 09:50
  • wsimport was used to compile the WSDL into Java. The `port` returned by `getNetSuitePort` is of type `NetSuitePortType`. We are using the 2014_2 platform. `port.setHeader`, and the `service.searchPreferences` option @NetSuiteExpert suggested is not available either. The `service` created is of type `NetSuiteService`. – the3rdNotch Feb 26 '16 at 14:44