The g_form.getControl method does not work on sc_req_item and sc_task tables. The functionality only works when using with g_sc_form.

Use of g_sc_form is not documented in Product Documentation.

Steps to Reproduce


Create the following variable:

  • Type: Single Line Text
  • Name: MyVariable
  • Question: MyVariable Question

Create a Catalog Client Script:

  • Type: OnLoad
  • Name: OL
  • Applies: check all 3 boxes
  • Script:

function onLoad() {
var myControl = g_form.getControl('MyVariable');

Then order the item and view the order. The following text alerts: undefined

Root cause: This functionality works at ordering due to the implementation of g_form being a ServiceCatalogForm.

This class generally supports the functionality outlined in Glide class overview.

However, after ordering, the g_form is a GlideForm. Not only does this implementation not correctly support the getControl method, as described in ServiceNow documentation, it is also responsible for other issues, such as long-running-script issues when using the setMandatory method.



The workaround is to make use of the g_sc_form object and call its getControl function.

The example below shows how to correctly check if g_sc_form is available before making use of getControl:

var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form; 
var myControl = form.getControl("VARIABLE"); 



Related Problem: PRB620307

Seen In

Calgary Patch 3 Hot Fix 1
Calgary Patch 7 Hot Fix 2
Dublin Patch 6
Eureka Patch 2
Eureka Patch 5
Fuji Patch 5
Fuji Patch 8

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2019-01-14 08:46:58