Search code examples
suitescriptsuitescript2.0

How to pass a value from getInputData() to map() function in map reduce suitescript?


I have made a suitelet that is running a map-reduce script and passing a parameter which is a date. Now what is required is to include that date object (coming from suitelet) in the map() function. So that the record that will be created in map() can have that date as trandate.

 define(['N/record', 'N/search', 'N/runtime'], function (record, search, runtime) {
  function getInputData() {
    try {
      var slfilter = runtime.getCurrentScript().getParameter({ name: 'custscript_searchfilter_date' });
      slfilter.replace(/\\/g, "");
      var dateSL = JSON.parse(slfilter);
      log.debug('dateSL parsed', dateSL)
      var date = dateSL['date'];
      log.debug('date', date);

      var savedSearch = search.load({ id: 'customsearch_wip_correction' });

      var results = getResults(savedSearch.run())
      log.debug('results:', results)      

      return results;
    }
    catch (e) {
      log.error("GetInputData ", e);
    }
  }

  function map(context) {

    try {
    // date is required here 
    var data = JSON.parse(context.value);
    log.debug('map:' + context.key, context.value)

    var amount = data.values['SUM(amount)'];
    log.debug('amount', amount)

    var location = data.values['GROUP(location)'][0].value;
    log.debug('location', location)
}
catch (e) {
  log.error("map", e)
}


 }

Solution

  • Put runtime.getCurrentScript().getParameter in map section.

    N/runtime can work in any endpoint either Client Script or User Events.