ConnectALL : Unable to map User fields such as Email/Employee Type for "Requested For" object associated with a Catalog Task in ServiceNow
search cancel

ConnectALL : Unable to map User fields such as Email/Employee Type for "Requested For" object associated with a Catalog Task in ServiceNow

book

Article ID: 405632

calendar_today

Updated On:

Products

ConnectALL ConnectAll On-Prem ConnectAll SaaS

Issue/Introduction

Problem Statement:

Integrating ServiceNow Catalog Tasks (sc_task) with external systems (e.g., Jira) presents a common challenge when comprehensive requestor details are required for accurate data synchronisation. By default, the Catalog Task table lacks direct fields for essential user attributes such as email, department, title, phone, location.

While the Requested For field is available as a reference from the parent Request Item (sc_req_item), it provides only the sys_id of the user object to the Catalog Task. This limitation prevents successful mapping and transfer of specific user information, which is critical for robust data integration and process automation.

This article details the necessary ServiceNow configuration changes to ensure these vital requestor details are directly accessible on Catalog Tasks, resolving this data/field mapping constraint.

Environment

3.x

Resolution

Solution / Workaround: Populating Requestor Details on Catalog Tasks

This solution involves a two-step configuration within ServiceNow:

  1. Creating Custom Fields on the Catalog Task (sc_task) table to store the desired requestor information.
  2. Implementing an Asynchronous Business Rule on the Request Item (sc_req_item) table to automatically populate these custom fields on associated Catalog Tasks whenever the 'Requested For' user changes or is initially set.

 

Step 1: Create Custom Fields on the Catalog Task Table

You will need to create a dedicated custom field on the sc_task table for each user attribute you wish to sync.

  1. Navigate to the Catalog Task Table Definition:
    • In the ServiceNow navigation filter, type sc_task.LIST and press Enter.
    • Right-click on any column header and select Configure > Table.
    • Alternatively, navigate to System Definition > Tables, search for sc_task, and open its record.
  2. Add New Fields (Columns):
    • Scroll down to the "Columns" related list.
    • Click the New button to add a new column.
    • Recommended Fields & Types:
      • Label: Requested For Email
      • Name: u_requested_for_email (auto-generated, ensure it's unique eg. u_requested_for_email)
      • Type: String (Length: 100 or 255)
    • Repeat this process for each desired user attribute.
    • Click Submit for each new field.

 

Step 2: Create an Asynchronous Business Rule on the Request Item Table

This Business Rule will trigger whenever the Requested For field on a Request Item (sc_req_item) is changed or set, and it will then populate the custom fields you created on all associated Catalog Tasks. Refer screen capture below.

  1. Navigate to Business Rules:

    • In the ServiceNow navigation filter, type sys_script.LIST and press Enter.
    • Click the New button.
  2. Configure the Business Rule:

    • Name: Populate Requested For Details on Catalog Tasks (or similar descriptive name)
    • Table: Request Item [sc_req_item]
    • When to Run:
      • When: Async(This is crucial for performance, as it runs in the background).
      • Order: (Leave default or set to a low number like 100)
      • Insert: Check this box.
      • Update: Check this box.
    • Filter Conditions:
      • Requested for changes

 

    • Advanced:
      • Paste the following code in script field.
(function executeRule(current, previous /*null when async*/) {
// This async Business Rule updates a custom field on all associated Catalog Tasks
// whenever the 'Requested for' on a Requested Item changes.
// --- Configuration ---
// Define the field on the User [sys_user] table you want to copy.
// Examples: 'department', 'location', 'title', 'phone'
var userAttributeToCopy = 'email';
// Define the custom field on the Catalog Task [sc_task] table to update.
var taskFieldToUpdate = 'u_checkbox22';

// Step 1: Get the new 'Requested for' user's information.
// We need to query the sys_user table to get the display value of the attribute.
var requestedForUser = new GlideRecord('sys_user');
if (!requestedForUser.get(current.requested_for)) {
// Log an error if the user record can't be found.
gs.logError('Could not find user with sys_id: ' + current.requested_for, 'UpdateTasksOnRITMChange');
return; // Exit the script.
}

// Get the display value of the attribute. Using getDisplayValue() is safer for reference fields.
var attributeValue = requestedForUser.getDisplayValue(userAttributeToCopy);
if (!attributeValue) {
attributeValue = 'N/A'; // Set a default value if the user's attribute is empty.
}

// Step 2: Find and update all associated Catalog Tasks.
var catalogTask = new GlideRecord('sc_task');

// Find all tasks linked to the current Requested Item.
catalogTask.addQuery('request_item', current.getUniqueValue());
catalogTask.query();

// Check if any tasks were found before proceeding.
if (!catalogTask.hasNext()) {
gs.info('No catalog tasks found for RITM ' + current.number + ' to update.', 'UpdateTasksOnRITMChange');
return;
}

var taskCount = catalogTask.getRowCount();
gs.info('Updating ' + taskCount + ' tasks for RITM ' + current.number + ' with ' + userAttributeToCopy + ': ' + attributeValue, 'UpdateTasksOnRITMChange');

// Loop through each task and update the custom field.
// Because this is an async rule, this update happens in the background.
while (catalogTask.next()) {
catalogTask.setValue(taskFieldToUpdate, attributeValue);
// You can add more complex logic here if needed. For example, only update active tasks.
// if (catalogTask.active == true) {
// catalogTask.update();
// }
catalogTask.update();
}
})(current, previous);

 

You are all set now to map Requested For Email field in ConnectALL automation.