|
| 1 | +# Global Manager Map in Transform Script |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This snippet demonstrates how to build and reuse a **global lookup map** across Transform Map scripts in ServiceNow — specifically, mapping **Manager Email → sys_id** from the `sys_user` table. |
| 6 | + |
| 7 | +By defining the map using `this.managerMap` in an **onStart Transform Script**, the data becomes available to **onBefore** or **onAfter** scripts during the same import execution, eliminating repetitive queries and improving performance. |
| 8 | + |
| 9 | +> **DISCLAIMER** |
| 10 | +> This script was developed and tested on a **ServiceNow Personal Developer Instance (PDI)**. |
| 11 | +> It is intended for **educational and demonstration purposes only**. |
| 12 | +> Please **test thoroughly in a non-production environment** before deploying to production. |
| 13 | +
|
| 14 | +--- |
| 15 | + |
| 16 | +## What it does |
| 17 | + |
| 18 | +- Preloads a dictionary of all system users (`sys_user` table) into memory. |
| 19 | +- Maps user **email addresses** (lowercased) to their corresponding **sys_ids**. |
| 20 | +- Shares the map globally across transform script stages (onStart → onBefore → onAfter). |
| 21 | +- Eliminates the need for repeated `GlideRecord` queries in each transform stage on each row. |
| 22 | +- Significantly improves transform performance when importing large data sets. |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## Prerequisites & Dependencies |
| 27 | + |
| 28 | +Before using this snippet, ensure that: |
| 29 | + |
| 30 | +1. **Transform Map Context** |
| 31 | + |
| 32 | + - The script must be placed in a **Transform Map > Script** (e.g., “onStart” or “Run Script”). |
| 33 | + - Other transform scripts in the same map (e.g., onBefore or transformRow) can then reference `this.managerMap`. |
| 34 | + |
| 35 | +2. **sys_user Table Access** |
| 36 | + |
| 37 | + - The transform user must have permission to **read** the `sys_user` table. |
| 38 | + |
| 39 | +3. **Valid Email Data** |
| 40 | + - Ensure the `sys_user.email` field is populated and unique for all users who may appear as managers. |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## Script Details |
| 45 | + |
| 46 | +- **Author:** Anasuya Rampalli ([anurampalli](https://github.com/anurampalli)) |
| 47 | +- **Version:** 1.0 |
| 48 | +- **Date:** 2025-10-10 |
| 49 | +- **Context:** Transform Map → Run Script (onStart) |
| 50 | +- **Tested On:** ServiceNow Personal Developer Instance (PDI) |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +``` |
| 55 | +
|
| 56 | +``` |
0 commit comments