-->

Get Items in a PurchaseOrder using SuiteTalk

2020-04-15 15:20发布

问题:

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?

回答1:

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);
                }
            }
        }
    }