Dynamic Description on Catalog Tasks
Overview
This document describes a method for dynamically populating the Short Description and Description fields of ServiceNow catalog tasks. By using a templating system with variable substitution, reference lookups, and conditional logic, administrators can create a more flexible and informative user experience without requiring manual input for every task.
The process is driven by two Business Rules that parse a template attached to a catalog item. This allows for automated population of task descriptions based on:
- Variable Substitution (
VAR): Directly inserts the value of a variable from the catalog item. - Reference Lookups (
REF): Performs a GlideRecord lookup to retrieve the display value of a referenced record. - Conditional Logic (
CONSW): Allows for different templates to be used based on the value of a specific variable.
Templates
The templating system supports two main types:
- Non-CONSW Templates: Used for simple, direct variable substitutions.
- CONSW Templates: Enables conditional logic to switch between different templates based on a variable’s value.
Non-CONSW Template Example
This template is for a simple access request, where values are populated directly from variables.
Short Description Template:
Request for VAR.access_level access to VAR.select_requested_folder_path.Description Template:
Please provide REF.requested_for(sys_user) VAR.access_level access to the folder path at VAR.select_requested_folder_path.
Provided Justification: VAR.Description.Example Output:
- Short Description:
Request for change access to T:\IT\SysLogs. - Description:
Please provide John Doe change access to the folder path at T:\IT\SysLogs. Provided Justification: I am needing access to this folder because I am a new engineer team member.
CONSW Template Example
The CONSW (Conditional Switch) template allows you to use different descriptions based on the value of a variable. In this example, a variable named action determines which of the four templates is used.
Short Description Template:
CONSW.action(new_server_virtual_machine_request:1,change_to_existing_server_virtual_machine:2,server_migration:3,decom_VM:4)
1)Provision Server: "VAR.name"
2)Modify Server: "VAR.what_is_the_name_of_the_server_you_are_requesting_a_change_for"
3)Migrate Server: "VAR.name_of_server_you_are_migrating_from"
4)Decommission Server: "VAR.server_to_be_decommissioned"
$)Description Template:
CONSW.action(new_server_virtual_machine_request:1,change_to_existing_server_virtual_machine:2,server_migration:3,decom_VM:4)
1)A request has been submitted to provision a new VAR.server_type server named "VAR.name" with the VAR.operating_system operating system.
The server is needed by VAR.date_needed_by.
2)A change to the "VAR.what_is_the_name_of_the_server_you_are_requesting_a_change_for" server is being requested.
The requested change is described as: VAR.what_is_the_change_being_requested.
Justification for this change is: VAR.justification.
This change is needed by VAR.date_needed_by.
3)A request has been submitted to migrate the server "VAR.name_of_server_you_are_migrating_from" to "VAR.name_of_server_you_are_migrating_to".
The migration will include the following: VAR.what_needs_to_be_migrated_services_accounts_printers_etc.
This migration is needed by VAR.date_needed_by.
4)A request has been submitted to decommission the server "VAR.server_to_be_decommissioned".
The reason for decommissioning is: VAR.reason_for_decommission.
The expected date of decommission is VAR.decommission_date.
$)Example Output:
- Short Description:
Provision Server: "MyNewServer01" - Description:
A request has been submitted to provision a new production server named "MyNewServer01" with the Windows Server 2022 operating system. The server is needed by 2025-05-30.
Example Output 2:
- Short Description:
Decommission Server: "SQLProd01" - Description:
A request has been submitted to decommission the server "SQLProd01". The reason for decommissioning is: This is an old server that has been replaced. The expected date of decommission is 2025-05-27.
Technical Implementation
This process is powered by two Business Rules that run on the sc_task table before a record is inserted. The dynamic description will only be applied if the description field is empty, which means any description set by a flow or another process will not be overwritten.
Note: Only one CONSW block per template is currently supported.
Handling Missing Values:
If a variable (VAR) or reference (REF) value cannot be resolved, the system replaces it with a blank string. This ensures that tasks are still created without errors, but it may result in empty sections in the description. For example:
Template: Please provide VAR.access_level access.
Output (if access_level is empty): Please provide access.
To avoid unclear task descriptions, ensure required variables are validated before submission.
| |