The g_form.getControl method does not work after ordering


Description

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:

Create a Catalog Client Script:

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

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.

 

Workaround

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