g_form.getReference does not work on the variable editor on sc_req_item RITM form, even when the Catalog Client Script is set to run on a requested item.

Steps to Reproduce


  1. Create a reference variable in a catalog item.
  2. Create a catalog client script for the catalog item.
  3. Type onChange.
  4. Select the variable created above, applies to catalog item and catalog requested item.
  5. Add these lines to the script field:

    function onChange(control, oldValue, newValue, isLoading) {
      if (isLoading) {
      console.log('test_var object: ' + g_form.getReference('test_var' /*, callback */));

  6. Open the catalog item from the Service Catalog homepage.
  7. Change the value of the variable. 
    The browser's console prints out test_var object: [object Object].
  8. Click Order Now.
  9. Navigate to the requested item created in default view.
  10. Change the value of the variable again.
    Note that the browser's console prints out test_var object: undefined, meaning that no object has been returned.


When writing script to access variables in a variable editor on regular forms, the object g_sc_form should be used for variable specific operations.

It is not always necessary, but in cases such as this, g_sc_form is needed for compatibility. The regular GlideForm object and the ServiceCatalogForm objects are intended to provide the same interface, but in some cases there are differences. GlideForm uses an asynchronous version of the getReference method that requires a callback. Note that the asynchronous approach is better as it avoids blocking on the client side. So, either use the following changes, see g_sc_form check, or change to use the asynchronous approach by using a callback, see the existing commented out block. 

function onChange(control, oldValue, newValue, isLoading) { 
  if (isLoading) { 

if (typeof g_sc_form != "undefined") 
  console.log('test_var: ' + g_sc_form.getReference('test_var' /*, callback */)); 
  console.log('test_var: ' + g_form.getReference('test_var' /*, callback */));  

Related Problem: PRB628968

Seen In

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

Fixed In

Fuji Patch 9

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2017-11-07 11:21:09