Is it possible to write to a script parameter via ...
# suitescript
k
Is it possible to write to a script parameter via suitescript?
I'm trying to set my map/reduce to get all records since the last time it ran
c
@Kris Wood Instead of writing a script parameter, can you search/query to get the data you need?
k
Only if I can get the last runtime
Trying to sync all message records to Salesforce via Boomi, need to get all IDs since the last runtime so Boomi can get them.
SuiteTalk doesn't seem to support search on message records
so I'm pushing them instead so Boomi can do a get on them
c
What do you mean about SuiteTalk's lack of message support in search? As for searching, we search "scheduledscriptinstance" to get the most recent map stage completion time for a feature, so that is possible at least 😄
@Kris Wood A different approach would be to put a date/time field on messages and populate it when you successfully sync it to Boomi. Filter for that in getInputData.
b
script parameters act as fields on the Script Deployment that you can manipulate via N/record
although the documentation does state this this use is unsupported
a more supported way is to put the date in a custom record somewhere that you load in the map/reduce
👍 1
k
yeah, I can read them just fine but setting them gets an unknown error
the custom record approach is what GPT suggested, but I thought there must be a more direct way
r
How is your map reduce script executed? Is it called by another script? If it is, you can set the parameter values via the API
k
It’s just scheduled every 15 minutes because I didn’t think messages had a user event ability
b
the more direct way is the N/record approach, which as mentioned, is unsupported
k
It didn’t
b
what did your code look like
k
Copy code
function getInputData() {
    try {
      // Get the last run time from the script parameter
      let lastRunTime = runtime.getCurrentScript().getParameter({
        name: 'custscript_last_run_time'
      });

      // If null, set to yesterday at midnight
      if (!lastRunTime) {
        lastRunTime = new Date();
        lastRunTime.setHours(0, 0, 0, 0);
        lastRunTime.setDate(lastRunTime.getDate() - 1);
      } else {
        lastRunTime = new Date(lastRunTime);
      }

      // Load the script deployment record to set the last run time
      var scriptDeployment = record.load({
        type: record.Type.SCRIPT_DEPLOYMENT,
        id: runtime.getCurrentScript().deploymentId
      });

      scriptDeployment.setValue({
        fieldId: 'custscript_last_run_time',
        value: new Date()
      });

      // Save the script deployment record
      scriptDeployment.save();

      // Search messages created after the last run time, the only column we need is internalid
      return search.create({
        type: 'message',
        filters: [
          ['created', 'after', lastRunTime]
        ],
        columns: ['internalid']
      });

    } catch (e) {
      log.error({
        title: 'Error in getInputData',
        details: e.toString()
      });
      throw e;
    }
  }
b
log
Copy code
runtime.getCurrentScript().deploymentId
k
it doesn't like .deploymentId. I bet GPT hallucinated it
b
does it look like the internal id of a record
b
did you do what i asked originally and log it
k
yeah it gives a missing semicolon error
Ok got it
gives a script_id not an internalid
customdeploy_exportmessages_mr
b
you should be able to do a search or query to get the internal id that you want to use
k
yeah, just an extra step
Got it! 😄