Catalog Client Scripts - Common Issues and ResolutionsIssue <!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Issue 1: Catalog Client Script May Not Work When document.getElementById() Is Used Symptoms A Catalog Client Script may not work or behave unexpectedly when document.getElementById() is used within the script. Release Any release Cause The method document.getElementById() performs direct DOM manipulation, which is not supported on the ServiceNow platform. Relying on the DOM in this way can cause inconsistent behavior across different browsers and browser versions. Resolution Use the g_form object instead of accessing the DOM directly. Direct DOM access can lead to compatibility issues between browsers and browser versions. Additionally, ServiceNow may change element names between platform versions, making direct DOM references unreliable. Instead of: document.getElementById('elementId').value Use: g_form.getValue('variable_name') Additional Information ServiceNow Docs: Unsupported Client Scripts Issue 2: Catalog Client Script Not Working on Service Portal Issue An onChange Catalog Client Script targeting a variable is not triggering or functioning correctly when accessed through the Service Portal. Cause The following misconfigurations in the script were identified as the root cause: The UI Type was set to Desktop instead of All.The Variable Name field in the script was left empty, so the onChange trigger had no variable to listen to. Resolution To resolve this issue, correct the following in the Catalog Client Script record: Set UI Type to All so the script runs on both the standard UI and the Service Portal.Set the Variable Name to the exact internal name of the variable whose change should trigger the script.Review and correct the script logic. If you are checking the value of a boolean variable, the comparison must use a string: Incorrect: if (newValue == true) Correct: if (newValue == 'true') Boolean variable values in Catalog Client Scripts are passed as strings, so the comparison must be made against the string 'true', not the Boolean true. Issue 3: onChange Catalog Client Script Not Consistently Populating Hidden Variables from a Reference Variable Issue An onChange Catalog Client Script is defined on a variable set to populate two hidden variables, employee_first_name and employee_last_name, based on the value selected for the reference variable employee_name. The script works intermittently: sometimes the hidden variables are populated correctly, and other times they remain empty even though employee_name has a value. Cause The issue occurs due to ACL (Access Control List) restrictions on the sys_user table. Specifically, the following out-of-box ACL is failing for certain users: /sys_security_acl.do?sys_id=7df70f39c0a801661fb9e679f553c760 This ACL requires the logged-in user to have at least one role in order to read sys_user records. When the requesting user has no roles assigned, the ACL denies read access and the client script cannot retrieve the employee first name and last name values, causing the variables to remain empty. Resolution The behavior is user-dependent. Users without any assigned role will fail the OOB ACL check and will not be able to read from sys_user, causing the client script to silently fail. To fix this, choose one of the following approaches: Assign an appropriate role to all users who may submit catalog requests, so they pass the existing ACL check.Create a custom ACL on the sys_user table that explicitly grants read access to users without roles, scoped appropriately to your organization's security requirements. Issue 4: Catalog Client Script Unable to Auto-Populate a Lookup Select Box Variable Issue A catalog item contains a Lookup Select Box variable referencing the cmn_cost_center table. A Catalog Client Script is used to auto-populate this variable based on the logged-in user's cost center. The variable does not get populated when the catalog item is opened. Steps to Reproduce Open or create a catalog item using sc_cat_item.do.Add a variable of type Lookup Select Box, referencing the cmn_cost_center table. Name it cost_center.Create a Catalog Client Script that uses setValues to populate the cost_center variable with a cmn_cost_center record.Open the catalog item.Observe that the cost_center variable is not auto-populated. Cause The issue is caused by access control restrictions on the cmn_cost_center table. When a user does not have read access to that table, the choices for the Lookup Select Box variable are not loaded. Since the choices are absent, the Catalog Client Script cannot set a value even if it runs successfully. Resolution There are two approaches to resolve this issue: Grant read access to the cmn_cost_center table for the affected users. Once the table is accessible, the choices will load correctly and the client script will be able to set the variable value.Change the variable type from Lookup Select Box to Single-Line Text. This removes the dependency on choice loading and the ACL restriction no longer blocks the auto-population logic. Related Checks Verify that the variable internal name used in the Catalog Client Script exactly matches the internal name defined on the variable record.If setting a value by choice, confirm that the choice internal value (not the label) is used in the script. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } All releases Resolution<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Please check under each issue listed separately