Automatically Assign Users to Roles Based on Category, Subcategory, and Item in Change Requests

Automatically Assign Users to Roles Based on Category, Subcategory, and Item in Change Requests

How to Automatically Assign Users to Roles Based on Category, Subcategory, and Item in Change Requests

Purpose

In enterprise environments, change approval requirements vary depending on the type and impact of the change. Typically, organizations define approval workflows that are dependent on the Category, Subcategory, and Item selected in the change request.

This script enables automatic assignment of named users to roles based on these criteria. It supports two major use cases:

  1. Automatically assigning users to roles in the change form.

  2. Simplifying approval workflows by using roles to represent approvers.

By configuring users into roles through this script, you can leverage these role names in your change workflow’s approval nodes, eliminating the need for complex condition trees.


Why Use Roles for Approvals?

Often, organizations maintain approval logic directly inside workflows using Conditional Nodes such as:


Condition: Category = X → Yes
    Subcategory = Y → Yes
        Item = Z → Route to Approver A

This approach becomes hard to scale when there are many combinations of category, subcategory, and item. Instead, this script acts as a dynamic condition handler, assigning the correct user to a predefined role (e.g., "IT Head Approval", "Line Manager"). You can then simply reference the role name in the workflow approval node, and the right user will be picked automatically.

This decouples business logic from the workflow and makes it easier to manage, audit, and update.


What This Script Does

The script reads the values of Category, Subcategory, and Item from the change request. Based on this combination, it:

  • Assigns users to roles like:

    • Change Owner

    • Line Manager

    • IT Head Approval

    • Change Reviewer

  • Disables the role fields to prevent manual overrides.

Once users are assigned to these roles, they can be referenced directly in approval workflows.


Script ( File attached)

Tip: Make sure the form field names (CATEGORY, SUBCATEGORY, ITEM and role names ) exactly match what's configured in your Change template.


How to Modify the Script

Add a New Category/Subcategory/Item Combination

  1. Add a new mapping block under categoryInfo for the desired values.

  2. Define the users to be assigned for each role.

Example:

"category_D": {
  "subcategory_D": {
    "item_D": {
      "Change_Owner": "Alex Roy",
      "Line_Manager": "Meena Gupta",
      "IT_Head_Approval": "Rahul Mehta",
      "Change_Reviewer": "Meena Gupta"
    }
  }
}

Add a New Role

If a new role like Security Head needs to be included:

  1. Add the key-value pair under each relevant item block.

  2. Add a corresponding $CS.setText() line in the script.

  3. Include the field in the $CS.disableField() call if it should be locked from user editing.

Example:

$CS.setText("Security Head", categoryInfo[cat][subcat][item]["Security_Head"]);
$CS.disableField(["Security Head"]);

Scaling This for Larger Organizations


We understand that maintaining this script manually is feasible for a handful of CSI combinations—say, 4 to 5. But what if your organization has hundreds of Category-Subcategory-Item combinations, each with different approval stakeholders?
We've got you covered, Refer Here to know 

Regards,
Nandakumar Balaji,
Senior Product Manager, Enterprise Service Management.

                  New to ADSelfService Plus?