title: Javascript sanity check of netsuite suitescript
body: <p>Currently, I have a Netsuite SuiteScript where I export saved searches to csv's. It runs but it's not reusable and I'd like to make it easier by just adding key-value pairs. I have to a lot of copy pasting and it's easy to forget to update to the latest iteration of the run. It's a scheduled search which means it runs every 15 minutes and makes it hard to debug and test.</p>
  <p>Right now, my code looks like this, but with more searches, and it's a pain is not reusable.</p>
  <pre><code>/**
  * @NApiVersion 2.x
  * @NScriptType ScheduledScript
  * @NModuleScope SameAccount
  */
  
  define(['N/task'],
  /**
  * @param {record} record
  * @param {search} search
  */
  
  function(task) {
  
  var FILE_ID = 2992639; 
  var SEARCH_ID = 2993;
  
  function execute(scriptContext) {
      //first search
      var searchTask1 = task.create({
          taskType: task.TaskType.SEARCH
      });
  
      searchTask1.savedSearchId = SEARCH_ID;
      searchTask1.fileId = FILE_ID;
      var searchTaskId1 = searchTask1.submit();
      
      //next search
      FILE_ID = 2992640;
      SEARCH_ID = 3326;
      var searchTask2 = task.create({
          taskType: task.TaskType.SEARCH
      });
  
      searchTask2.savedSearchId = SEARCH_ID;
      searchTask2.fileId = FILE_ID;
      var searchTaskId2 = searchTask2.submit();
      
          //next search
      FILE_ID = 2992634;
      SEARCH_ID = 3327;
      var searchTask3 = task.create({
          taskType: task.TaskType.SEARCH
      });
  
      searchTask3.savedSearchId = SEARCH_ID;
      searchTask3.fileId = FILE_ID;
      var searchTaskId3 = searchTask3.submit();
      
      //this pattern repeats 19 times total. 
  
  }
  
  return {
      execute: execute
  };
  });
  </code></pre>
  <p>I've tried to code below</p>
  <pre><code>/**
  * @NApiVersion 2.x
  * @NScriptType ScheduledScript
  * @NModuleScope SameAccount
  */
  
  define(['N/task'],
  /**
  * @param {record} record
  * @param {search} search
  */
  
  function(task) {
  
      const searchList = {
          2993:2992639,
          3326:2992640,
          3327:2992634
      };
  
      function execute(scriptContext) {
          for (const [key, value] of Object.entries(searchList)) {
              var searchTask = task.create({
                  taskType: task.TaskType.SEARCH
              });
  
              searchTask.savedSearchId = $key;
              searchTask.fileId = $value;
              var searchTaskId = searchTask.submit();
          }
      }
  
      return {
          execute: execute
      };
  });
  </code></pre>
  <p>but get the following error, and I'm not sure what is wrong with my syntax. Netsuite makes it hard to tell what I'm doing wrong, so I'm hoping someone can help here. Thanks!</p>
  <pre><code>{&quot;type&quot;:&quot;error.SuiteScriptError&quot;,&quot;name&quot;:&quot;SSS_MISSING_REQD_ARGUMENT&quot;,&quot;message&quot;:&quot;task.submit: Missing a required argument: SearchTask.savedSearchId&quot;,&quot;stack&quot;:[&quot;createError(N/error)&quot;,&quot;execute(/SuiteScripts/dashboardreports.js:224)&quot;,&quot;createError(N/error)&quot;],&quot;cause&quot;:{&quot;name&quot;:&quot;SSS_MISSING_REQD_ARGUMENT&quot;,&quot;message&quot;:&quot;task.submit: Missing a required argument: SearchTask.savedSearchId&quot;},&quot;id&quot;:&quot;&quot;,&quot;notifyOff&quot;:false,&quot;userFacing&quot;:true}
  </code></pre>