Workflow Scratchpad Tip

When working with the Workflow scratchpad object it is important to note a couple of things:

  1. Data can be placed on the Scratchpad for later use using the format of workflow.scratchpad.insert_new_var_name_here
  2. You can create variables on the Scratchpad that are any type (e.g. String, Array, Object, etc). This allows for great flexibility, in my previous post, I demonstrate that you can put an array of objects as a scratchpad variable. By utilizing this method, you have an extensible method to retrieve as much data from the workflow as you would ever need.
  3. The Scratchpad can be retrieved from external sources such as Business Rules and Script Includes by first grabbing the Workflow’s contexts (script below shows this method):
var req_item_id = 'id you are looking up';
var item = new GlideRecord('sc_req_item');
if ({
var scratchpad_var = context.scratchpad.your_var_name_here;
//do something with the scratchpad data here

Note, that you can also place data on the Scratchpad using a “Display” Business Rule, and then retrieve on the client side with a Client Script (“onLoad”).


For More information please see the following ServiceNow Wiki articles:

5 thoughts on “Workflow Scratchpad Tip”

  1. Hi, thank you for posting this. It helped me a lot with an issue I was working on regarding storing data in the scratchpad.

  2. Valuable ServiceNow Workflow tip. Lucky me I found your site by accident, saved me a lot of time and effort in dealing with workflows and exchanging data!

  3. I tried the same in script Include,

    checkworkflow: function() {
    //get the workflow script include helper
    var msg = ”;
    var workflow = new Workflow();
    //get the requested items workflow context
    //this will get all contexts so you’ll need to get the proper one if you have multiple workflows for a record
    var context = workflow.getContexts(current);
    //make sure we have a valid context
    if ( {
    //get a value from the scratchpad
    msg = context.scratchpad.important_msg;
    //msg now equals “scratch me”, that was set in the run script activity
    gs.log(“Hello World “+ msg +’ ‘+current.number);

    Log output is like : Hello World undefined RITM0010051

    In RUn Script Activity it is already declared as : workflow.scratchpad.important_msg = ‘showUIaction’;

    1. Hi Shilpa,

      Not sure if you got this figured out, but there are a couple of things to consider:
      1. You are not passing the “current” object to your “getContexts(current)” function
      2. Ensure that “current” is an actual “task” record at the time you’re calling the Script Include
      3. Since “msg” is undefined you will want to make sure that your “getContexts(current)” is returning the proper/expected workflow

  4. Hi Max,

    Thanks for your reply.

    Yes I got the code working. it was to do with the right value being passed to getContext.

Leave a Reply

Your email address will not be published. Required fields are marked *