OOTB Client Scripts in Service Portal: Classic API IncompatibilitiesIssue OOTB Client Scripts with **UI Type: "All"** sometimes fail in Service Portal contexts (Employee Center, Service Portal portals) with `ReferenceError: GwtMessage is not defined` or `TypeError: Cannot read properties of null`, even though they work in Classic UI. Root cause: scripts use Classic-only APIs unsupported in Service Portal runtime. **Example:** SAM "Set notify_user hint" script uses `GwtMessage` and `document.getElementById()`, which don't exist in Service Portal. Release Yokohama. Cause Service Portal intentionally restricts certain APIs for security/performance: **Unsupported in Service Portal:** - `GwtMessage` (Classic messaging) - `document`, `window` (browser globals) - `control`, `$`, `$$` (Classic form controls) OOTB scripts set to UI Type "All" must work in both Classic and Service Portal. If written for Classic only, they fail in Service Portal. **Not a customer issue — OOTB design limitation.** Resolution ## Solutions **Option A — UI Type: Desktop (quick fix)** - Change script's UI Type from "All" to "Desktop" - Prevents execution in Service Portal; console error disappears - Trade-off: script behavior won't run in Employee Center **Option B — Rewrite for SP compatibility (lasting fix)** - Replace `GwtMessage` → `getMessage()` (callback-based) - Replace `document.getElementById()` → `g_form.getElement()` - Use feature detection to branch on runtime: ```javascript if (typeof GwtMessage !== 'undefined') { // Classic path } else if (typeof g_form !== 'undefined') { // Service Portal path } ``` **Option C — Apply official patch** - Check for published Update Set from product team - Import, preview, commit - Example: SAM had official patch for "Set notify_user hint" --- ## When This Occurs - OOTB scripts in Employee Center (SAM, ITOM, other modules) - Form widgets displaying records in Service Portal - Symptom: console error in SP context only, not Classic UI --- ## Diagnostic Checklist 1. Confirm error only in Employee Center/Service Portal (not Classic Form) 2. Identify script name from console error 3. Check script's UI Type (if "All", verify Classic API usage) 4. Search code for `GwtMessage`, `document.getElementById()`, `window`, `control` 5. Check if OOTB (packaged) or custom 6. If OOTB, search for official patch/defect Related Links - ServiceNow Docs: [Service Portal Unsupported APIs](https://www.servicenow.com/docs/r/zurich/platform-user-interface/service-portal/unsupported_client_scripts.html) - ServiceNow Docs: [Service Portal Client Script Reference](https://www.servicenow.com/docs/r/platform-user-interface/service-portal/client-script-reference.html)