2

我正在尝试使用 SuiteTalk 从采购订单中获取项目和一些相关信息。我可以TransactionSearch在 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)  

我能够将每个结果作为 PurchaseOrder 类的实例转换为记录。

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 {...}  
  }
}

从这里我可以使用 getter 访问各个字段,但 ItemList 除外。

我可以在 NetSuite Web 界面中看到采购订单附加了一些项目。但是getItemList,在结果记录上使用总是返回null响应。

有什么想法吗?

4

1 回答 1

3

我认为您没有使用搜索首选项,这就是您无法获取采购订单行项目的原因。您必须在代码中使用以下搜索首选项 -

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

        _service.searchPreferences = prefrence;

以下是使用上述首选项的工作示例 -

    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);
                }
            }
        }
    }
于 2016-02-25T09:08:53.413 回答