3

我在 Netsuite 中创建了一个保存的搜索。我正在尝试通过我的应用程序中的 Web 服务调用来获取字段值。我正确地获取了总记录大小,但是在尝试获取字段值时,我保存的搜索中的所有字段(例如,项目名称)都为空。这是代码:

TransactionSearchAdvanced tsa = new TransactionSearchAdvanced();
tsa.setSavedSearchId("825");
SearchResult result = _port.search(tsa);
System.out.println("size of recds..." + result.getTotalRecords());

if (result.getTotalRecords() > 0) {
    // retain the search ID in order to get more pages 
    String sSearchId = result.getSearchId();
    SearchRowList rowList = result.getSearchRowList();
    processRowList(rowList);
    int iNumPages = result.getTotalPages();
    System.out.println("pages" + iNumPages);
    for (int i = 2; i <= iNumPages; i++) {
        result = _port.searchMoreWithId(sSearchId, i);
        rowList = result.getSearchRowList();
        System.out.println("jjjj" + rowList);
        processRowList(rowList);
    }
}

_port.logout();

public void processRowList(SearchRowList rowList) {
    try {
        System.out.println("inside process...." + rowList);
        for (int i = 0; i < rowList.getSearchRow().length; i++) {
            TransactionSearchRow ts = (TransactionSearchRow) rowList.getSearchRow(i);
            TransactionSearchRowBasic tsb = ts.getBasic();
            SearchColumnSelectField[] scsf = tsb.getItem();
            for (SearchColumnSelectField sf: scsf) {
                RecordRef rf = sf.getSearchValue();
                System.out.println("itemname:::" + rf.getName());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
4

2 回答 2

1

我是 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 文档而感到绝望的人!(虽然,这只是我的意见)

于 2016-02-08T01:24:59.277 回答
0

这是一个执行搜索并循环遍历结果并将子公司名称(记录 = 子公司,字段名称 = 名称)分配给变量的示例。每次出现循环时都会重新分配变量值,仅用于说明目的。

认为您正在寻找getFieldValue函数。

提示:使用 NetSuite 记录浏览器和模式浏览器获取有效的记录和列列表。

var rec = '';
var subsidiaryName = '';
var searchResults = nlapiSearchRecord( 'subsidiary', null, null, null );
for ( var i = 0; i < Math.min( 100, searchResults.length ); i++)
{
    var record = nlapiLoadRecord(searchResults[i].getRecordType(),searchResults[i].getId() );
    subsidiaryName = record.getFieldValue('name');
}
于 2015-06-24T00:16:34.027 回答