Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
The g_form.getControl method does not work after ordering - Known Error
  • >
  • Knowledge Base
  • >
  • Known Error (Knowledge Base)
  • >
  • The g_form.getControl method does not work after ordering
KB0547171

The g_form.getControl method does not work after ordering


16411 Views Last updated : Apr 7, 2024 public Copy Permalink English (Original)
  • English (Original)
  • Japanese
KB Summary by Now Assist

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:

  • 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');
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

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.