简体   繁体   English

从Netsuite中的保存搜索获取字段值为空

[英]Getting Fields Values as Null from Saved Search in Netsuite

I created a saved search in Netsuite. 我在Netsuite中创建了一个已保存的搜索。 I'm trying to get the field values through the web services call from my application. 我正试图通过我的应用程序的Web服务调用获取字段值。 I am getting total records size correctly, but while trying to get the fields values I'm getting null for all fields(example, itemname) from my saved search. 我正确地获得了总记录大小,但在尝试获取字段值时,我从保存的搜索中获取所有字段(例如,itemname)的null。 Here is the code: 这是代码:

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

I am new to Netsuite but I was desperate trying to solve the same problem, and I think I have the answer. 我是Netsuite的新手,但我非常渴望解决同样的问题,我想我有答案。 I think that, when you try to print the items names, you are trying to iterate over all the possible fields that a row may have. 我认为,当您尝试打印项目名称时,您试图迭代一行可能具有的所有可能字段。 However, this "item" object that the TransactionSearchRowBasic contains is not the list of items that this object may contain. 但是,TransactionSearchRowBasic包含的此“item”对象不是此对象可能包含的项目列表。 Then, you must try to get the values that your transaction saved search do contain. 然后,您必须尝试获取事务保存搜索所包含的值。

So, let's say that I have a transaction saved search in which I want to show the transaction's period, type, account, amount, date, and the external ID of the related department. 所以,假设我有一个交易保存搜索,我想在其中显示交易的期间,类型,帐户,金额,日期和相关部门的外部ID。 First, I looked in this link for the API ID of each record compared to it's UI name: 首先,我在此链接中查找了每个记录的API ID与其UI名称的比较:

https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2012_2/Records/transaction.html https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2012_2/Records/transaction.html

Then I used a very similar java code as yours but with some fixes. 然后我使用了一个非常类似的java代码,但有一些修复。

This method verifies that everything is ok and calls the method that really prints the data fields: 此方法验证一切正常并调用真正打印数据字段的方法:

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

This method handles the printing of my transaction's period, type, account, amount, date, departmentName fields: 此方法处理我的事务的期间,类型,帐户,金额,日期,部门名称字段的打印:

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

Notice that I had to create a DepartmentSearchRowBasic as I am trying to get the department external ID from the Department record. 请注意,我必须创建一个DepartmentSearchRowBasic,因为我试图从Department记录中获取部门外部ID。 In my saved search, I selected that department external ID with the "Department Fields..." option. 在我保存的搜索中,我使用“部门字段...”选项选择了该部门外部ID。

If you get lost with which method over your TransactionSearchRowBasic object will return you the correct field you selected in your saved search result, you can use Eclipse's debug mode to see which fields are not null and what types they return and contain. 如果您丢失了TransactionSearchRowBasic对象上的哪个方法将返回您在保存的搜索结果中选择的正确字段,则可以使用Eclipse的调试模式来查看哪些字段不为空以及它们返回和包含哪些类型。

Hope this answer helps all people desparate with the lack of good Netsuite documentation! 希望这个答案可以帮助所有人因缺乏优秀的Netsuite文档而绝望! (Though, that's only my opinion) (虽然,这只是我的意见)

Here is an example that performs a search and loops through the results and assigns the Subsidiary name ( Record = Subsidiary, Field Name = name ) to a variable. 下面是一个执行搜索并循环显示结果的示例,并将子公司名称(Record = Subsidiary,Field Name = name)分配给变量。 The variable value is re-assigned with each occurrence of loop and for illustration purposes only. 每次出现循环时重新赋值变量值,仅用于说明目的。

I think you were looking for the getFieldValue function. 你正在寻找getFieldValue函数。

Hint : Use the NetSuite Records Browser & Schema Browser for a valid list of records and columns. 提示 :使用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');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM