Enable use of variables in Change Task

General Add comments

Having workflow variables on catalog tasks has been possible for a long time in Service-now, but this functionality has never been applied to change tasks.
With some “simple” adjustments you can modify the change task definition to enable variables on these types of tasks.
This gives you the flexibility of configuring and capturing a different information set on a per task basis.

You need to have a couple of components in place:

  1. A workflow activity variable to capture variables per change task in the workflow designer
  2. A script to link the variables to the change task when the workflow is triggered
  3. A field/formatter to enable the display of the variables on the change task
  4. …and last but not lease, the variable itself

How you tie all of the above components together will be explained in the below paragraphs.

Technical configuration

The majority of the configuration is done in the activity definition. Go to “Workflow Editor > Activity Definitions” and open the definition for “Create Task”.

First of all you need to create a placeholder on the activity form which is used within the workflow editor. Add the bottom of this form a list is displayed with the activity variables. This is where the placeholder for the change task variables must be added. Create an activity variable which can hold an array. In this case I created a field called task_questions, used the type “glide_list” and have it reference the table “question”. This table will eventually hold the definition of the variables used on change tasks.

After the creation of this activity variable we can turn our attention to the script. The below two script should be added to the script container.

The first script invokes the function with the relevant taskID. The relation between change task and change task variable is captured in the question_answer table via the second script. The relation between these two entities is based on three parameters:

  1. question: A reference to the variable itself
  2. table_name: A reference to the table being referenced
  3. table_sys_id: A reference to the change task id

This table will also hold the value which is provided by an operator during the execution of the workflow and could be made available for reporting purposes, if required.


_setVars: function(taskID){
   var questions = activity.vars.task_questions;
   questions = questions.split(“,”);
      var qa = new GlideRecord(“question_answer”);
      qa.question = questions[i];
      qa.table_name = activity.vars.task_table;
      qa.table_sys_id = taskID;

When all the modifications have been completed on the activity definition, the attention can be turned to creating a new UI Formatter for the table change_task. The module can be found via “System UI > Formatters“. When creating the formatter use “com.glideapp.questionset.DefaultQuestionEditor” and apply it to the table “change_task”. The name will become available in the list of “Personalize Form Layout” page. Finally, add this newly created field/formatter to the change task form.

By finishing this final step the technical configuration is complete and it’s ready to be used.

Functional configuration

The functional configuration is realized by following the below steps.

  1. Configure/add your variables to the question table (question.list).
  2. Create/open a workflow for a change request and open a task. On this form you can find the field you have created in an earlier stage. Select the questions you have created and save the task.

After these steps have been completed, a change can be created and checkout the fruits of your work.
Based on the same building blocks, this functionality can also be applied to other modules within the application.

Please let me know if you have any questions.
You can contact me by mail frans.van.der.sar@2e2.nl

6 Responses to “Enable use of variables in Change Task”

  1. Brajendra Says:

    Hi Frans,

    Thanks for the great post. I was in the need of the same thing. I have one doubt here:
    Your Comment: After the creation of this activity variable we can turn our attention to the script. The below two script should be added to the script container.

    I have doubt that which script container you are reffering to. is it the script part of activity variable or change_task activity in workflow or workflow activity definition.

    Brajendra Gupta

  2. Frans Says:

    Hi Bajendra,

    The script portion should be added to the workflow activity definition.

    The first two lines should be part of the onExecute functionm, as it helps build the task definition when the workflow hits the activity. The second part is a seperate function.

    Hope this helps you out.



  3. Brajendra Says:

    Thanks Frans. That was helpful.

    I was wondering if it is possible to show change request variables in change task as it is possible in catalog requests.

  4. Anshul Says:

    Hi Frans,

    I am able to get the questions selected in the create task activity, but what if we want the questions dynamically based on the variables defined for the routine change ?

    Also, the shared procedure does not display the answers to the questions in the task form. Can you help with that as well.


  5. Bhanu Says:

    Tried the same in helsinki and doesn’t seem to work. Is this valid in helsinki aswell.

  6. Bhanu Says:

    Observed a bug in helsinki, When we add new variables in activity definition. The temporary var table name is not the same as the other fields which are. So the new variable cannot be added to the form.

Leave a Reply