2016-09-08 1 views
0

Map/ReduceスクリプトのgetInputDataメソッドで検索をロードしました。 とし、MapメソッドとgetInputDataメソッドで検索を実行しようとしました。「N/search」モジュールを使用して作成された検索は、Map/Reduce Scriptで実行できますか?

ユーザイベント、スケジュールスクリプト、クライアントスクリプト、Suitletスクリプトのような通常のスクリプトで

、すべて我々が検索を作成し、検索使用して、実行()またはrunPaged()メソッドを実行することができます。

私の質問は、getInputDataメソッドまたはMap/Reduce Script?のrun()メソッドまたはrunPaged()メソッドを使用して検索を実行できることです。

If検索結果列を次の段階、つまり[マップ]または[縮小]に渡す方法を意味します。

マイコード:事前に

define(['N/error', 'N/record', 'N/search', 'N/log', 'N/task', 'N/runtime', 'N/email'], 
     /** 
     * @param {email} email 
     * @param {record} record 
     * @param {runtime} runtime 
     * @param {search} search 
     * @param {task} task 
     * @param {transaction} transaction 
     */ 

     /* this script is used to create the search on the invoice and store the obtained search results on the object and trying to create the another search based on the values on the object */ 
     function(error, record, search, log, task, runtime, email) { 

      function getInputData() { 

       log.debug("Get Input", "Initiated"); 
       //Invoice Search 
       var invoiceSearch = search.load({ 
        id: 'customsearch_invoice_calc' 
       }); 

       log.debug("invoiceSearch:", invoiceSearch); 

       //Creating the Object for Storing Search Results 

       var invoiceDetails = {}; 
       var invoiceId = "Id"; 
       var invoiceLineId = "invoiceLineId"; 

       //Running the Search 
       var myPagedData = invoiceSearch.runPaged({ 
        "pageSize": 1000 
       }); 
       log.debug('myPagedData:', myPagedData); 

       myPagedData.pageRanges.forEach(function(pageRange) { 

        // Fetch the results on the current page 
        var myPage = myPagedData.fetch({ 
         index: pageRange.index 
        }); 
        log.debug('myPage:', myPage); 
        // Iterate over the list of results on the current page 
        myPage.data.forEach(function(result) { 

         // Process the individual result 
         invoiceDetails[invoiceId] = result.getValue({ 
          name: 'internalid' 
         }); 
         invoiceDetails[invoiceLineId] = result.getValue({ 
          name: 'line' 
         }); 
        }); 
       }) 

       log.debug("invoiceDetails:", invoiceDetails); 
       return invoiceSearch; 
      } 

      function map(context) { 
       log.debug("Map", "Initiated"); 
       var searchResult = JSON.parse(context.value); 


       var invoiceId = searchResult.id; 
       var lineId = searchResult.values.line.value; 
       log.debug("invoiceId:", invoiceId); 
       log.debug("lineId:", lineId); 
       comCalulation(invoiceId, invoiceId); 


       context.write(invoiceId); 
      } 

      function commissionCalc(invoiceId, lineId) { 
       log.debug("Entered:", "Commission Calc Function"); 
       log.debug("invoiceId - Inside Commission Calc:", invoiceId); 
      } 

      function reduce(context) { 
       log.debug("Reduce", "Initiated"); 

      } 



      function summarize(summary) { 
       log.debug("summarize", "Initiated"); 

      } 

感謝。

答えて

3

getInputDataからmapに検索結果を渡す場合は、検索オブジェクトをgetInputDataに戻すだけです。 NetSuiteは自動的に検索を実行し、Map/Reduce Scriptレコードの設定に応じてmapまたはreduceフェーズに結果を配布します。

この例は、NS Helpの「Map/Reduce Script Type」というページの「例2」に示されています。私はここでその一部を再現しました:

function getInputData() 
{ 
    // Input phase only needs to create/load and return search object 
    return search.create({ 
     type: record.Type.INVOICE, 
     filters: [['status', search.Operator.IS, 'open']], 
     columns: ['entity'], 
     title: 'Open Invoice Search' 
    }); 
} 

function map(context) 
{ 
    // Parse individual search result 
    var searchResult = JSON.parse(context.value); 
    var invoiceId = searchResult.id; 
    var entityId = searchResult.values.entity.value; 

    applyLocationDiscountToInvoice(invoiceId); 

    // Pass customerId:invoiceId to the reduce phase 
    context.write(entityId, invoiceId); 
} 

あなたは、個々の検索結果がcontext.valueとして一緒に渡され、オブジェクトに解析する必要があります見ることができます。 mapが検索結果ごとに1回呼び出されます。

関連する問題