我是 Netsuite 的新手,但我很想解决同样的问题,我想我有答案。我认为,当您尝试打印项目名称时,您正在尝试遍历行可能具有的所有可能字段。但是,TransactionSearchRowBasic 包含的这个“项目”对象不是该对象可能包含的项目列表。然后,您必须尝试获取您的事务保存搜索确实包含的值。
所以,假设我有一个交易保存搜索,我想在其中显示交易的期间、类型、帐户、金额、日期和相关部门的外部 ID。首先,我在此链接中查看了每条记录的 API ID 与它的 UI 名称相比:
https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2012_2/Records/transaction.html
然后我使用了与您的非常相似的 java 代码,但有一些修复。
此方法验证一切正常并调用真正打印数据字段的方法:
public void printTransactionRowFields() throws ExceededUsageLimitFault, UnexpectedErrorFault, InvalidSessionFault, ExceededRecordCountFault, RemoteException, UnsupportedEncodingException, SOAPException
{
TransactionSearchAdvanced tsa = new TransactionSearchAdvanced();
//This is my Transaction saved search Internal ID
String savedSearchID = "999";
tsa.setSavedSearchId(savedSearchID);
SearchResult srr = _port.search(tsa);
boolean isSuccess = srr.getStatus().isIsSuccess();
System.out.println("Search result: "+ isSuccess);
int searchNumRecords = srr.getTotalRecords();
System.out.println("Amount of records: "+ searchNumRecords);
if (isSuccess)
{
if(searchNumRecords > 0)
{
int iNumPages = srr.getTotalPages();
//Must check the amount of pages to process every record
System.out.println("Num pages: "+ iNumPages);
//Must retain search ID to search for more pages. This is a web service ID, it's not the same as the internal ID "999"
String sSearchID = srr.getSearchId();
System.out.println("Search id: " + sSearchID);
SearchRowList rowList = srr.getSearchRowList();
System.out.println("Num rows in row list 1: " +rowList.getSearchRow().length);
processReportRowList(rowList);
//We process the next iNumPages pages (it's not 0 index)
for ( int i=2; i<=iNumPages; i++) {
//Users who authenticate to NetSuite by providing their credentials in the SOAP header of
//their requests must use searchMoreWithId to retrieve search results that span multiple pages.
//They cannot use searchMore or searchNext, since both operations require an active session.
//(For information on request-level-credential authentication, see Request-Level Credentials.)
srr = _port.searchMoreWithId(sSearchID, i);
rowList = srr.getSearchRowList();
System.out.println("Num rows in row list #" +i+": " +rowList.getSearchRow().length);
processReportRowList(rowList);
}
}else{
System.out.println("This saved search contains no records to process.");
}
}
else{
System.out.println("Search could not find Transaction Saved Search with id: " + savedSearchID);
}
}
此方法处理我的交易期间、类型、帐户、金额、日期、部门名称字段的打印:
public void processReportRowList(SearchRowList rowList)
{
if(rowList!= null){
System.out.println("Search row length: " + rowList.getSearchRow().length);
for (int i=0; i<rowList.getSearchRow().length; i++) {
TransactionSearchRow row=(TransactionSearchRow)rowList.getSearchRow(i);
TransactionSearchRowBasic basic= row.getBasic();
System.out.println((basic==null)?"Basic is Null.":"Basic is not null.");
RecordRef period = basic.getPostingPeriod(0).getSearchValue();
String periodInternal = period.getInternalId();
String type = basic.getType(0).getSearchValue();
RecordRef account = basic.getAccount(0).getSearchValue();
Double amount = basic.getAmount(0).getSearchValue();
Double amountFC = basic.getFxAmount(0).getSearchValue();
Calendar tranDate = basic.getTranDate(0).getSearchValue();
DepartmentSearchRowBasic deparmentRow = row.getDepartmentJoin();
String departmentExternalID = deparmentRow.getExternalId(0).getSearchValue().getInternalId();
//Print results
System.out.println("Row# "+i+"\n"+"Period Internal ID: "+periodInternal +"\n Type: "+ type+ "\n Account Internal ID: "+
accountInternal + "\n Amount: "+ amount + "Foreign Currency Amount: "+ amountFC + "\n Date: " + tranDate.getTime().toString()+
"\n Department External ID: "+departmentExternalID);
}
}else{
System.out.println("Row list arrived null");
}
}
请注意,当我试图从部门记录中获取部门外部 ID 时,我必须创建一个 DepartmentSearchRowBasic。在我保存的搜索中,我使用“部门字段...”选项选择了该部门的外部 ID。
如果您不知道 TransactionSearchRowBasic 对象上的哪种方法将返回您在保存的搜索结果中选择的正确字段,您可以使用 Eclipse 的调试模式来查看哪些字段不为空以及它们返回和包含哪些类型。
希望这个答案可以帮助所有因缺乏良好的 Netsuite 文档而感到绝望的人!(虽然,这只是我的意见)