The CreatorCon Call for Content is officially open! Get started here.

Suzanne Smith
ServiceNow Employee
ServiceNow Employee

For many of you, Service Catalog is a critical feature. You spend a lot of time adding and editing Service Catalog items to provide your users with the right service and product choices. While maintaining items, you may frequently edit variables and catalog UI policies on your items.

Variables enable you to offer users choices when they order catalog items. In the example below, the Report Performance Problem catalog item contains three variables that enable your users to specify an application, describe the slowdown, and list particular transactions that are slow:

service_catalog_UI_policy1.gif

UI policies give you a mechanism for dynamically changing information on a form with having to use client scripts. In the example below (using the Report Performance Problem catalog item again), if users describe the nature of the slowdown as All operations within the application are slow, a UI Policy removes the text box for describing the particular transactions that are slow:

service_catalog_UI_policy2.gif

Cannot update existing request item records

In some versions of ServiceNow, users are experiencing an issue after they add a new variable or UI policy to an existing catalog item that has outstanding requests. If a fulfiller opens one of the existing request item records, the following error appears:

TypeError: g_form.getAppliedFieldName is not a function

Uncaught TypeError: g_form.getAppliedFieldName is not a function

GlideFieldPolicy._debugAction @ ui_policy.jsx?v=04-09-2016_1519:722

GlideFieldPolicy._runAction @ ui_policy.jsx?v=04-09-2016_1519:619

GlideFieldPolicy.runActions @ ui_policy.jsx?v=04-09-2016_1519:577

GlideFieldPolicy.runPolicy @ ui_policy.jsx?v=04-09-2016_1519:37

GlideFieldPolicy.runPolicyOnLoad @ ui_policy.jsx?v=04-09-2016_1519:32

ui_policy_onLoad @ ui_policy.jsx?v=04-09-2016_1519:741

runBeforeRender @ js_includes_doctype.jsx?v=04-09-2016_1519&lp=Tue_May_24_10_48_15_PDT_2016&c=4_62:404

(anonymous function) @ z_last_include.js:10

(anonymous function) @ z_last_include.js:16

Broken references to variables in the catalog UI policies are causing the problem. The system does not know about new variables added to the item. Answers to the variables are inserted into the sc_item_option table during the ordering process, but the sc_item_option table does not have an entry for the new variables.

service_catalog_UI_policy3.gif

Also, UI policies are defined on the item level and run on req-item, so the system does not know:

  • how to render the new variable on req-item and task form
  • that a particular UI policy should not be loaded

There is no workaround for this issue, so upgrading to one of the versions where the issue is fixed is your best bet. For the most current information about versions in which this issue has been seen and has been fixed, view the known error article associated with the problem: KB0596179 - Catalog UI policy on a new variable on a catalog item causes error on existing request i.... You can subscribe to the known error article and be automatically notified when there are changes (such as the addition of new "fixed in" versions) by clicking the Subscribe button in the upper right corner of the article.

To help you find the broken references, we can offer the following script. This script finds the broken variable references and prints out the URL for the catalog ui policy actions that have broken references.

function findBrokenPolicies() {


      var cupaIDStr = "";

      var gr = new GlideRecord('catalog_ui_policy_action');
      gr.addActiveQuery();
      gr.query();   //Query the entire list of catalog UI Policy Actions to find the catalog_variable value

      while (gr.next()) {

              var cv = gr.catalog_variable.getDisplayValue();
              var sID = cv.split('IO:')[1];   // Remove the IO: from the value in the catalog_variable IE: IO:d4892e556f081d00362401dfde3ee496
              var upaName = gr.sys_name;
              var upaID = gr.sys_id;
              var gr2 = new GlideRecord('item_option_new');
              gr2.addActiveQuery();

              if (!gr2.get(sID)) {
                      cupaIDStr += upaID + ","; // If the queried record does not exist, we add it to the cupaIDStr (cupa = Catalog UI Policy Action)
              }

              gr2 = new GlideRecord('sc_item_option_mtom');
              gr2.addQuery('sc_item_option.item_option_new.sys_id', sID);
              gr2.query();

              if (!gr2.next()) {
                      cupaIDStr += upaID + ","; // If the queried record does not exist, we add it to the cupaIDStr (cupa = Catalog UI Policy Action)
              }

      }

      var cupaIDList = cupaIDStr.substring(0, cupaIDStr.length - 1);    

      // If a match is found, we print out the URL, else we print out no matches found

      if (cupaIDList.length > 0) {
              gs.print("Catalog UI Policy Actions with broken references can be found in the following location: ");
              var cupaURL = "/catalog_ui_policy_action_list.do?sysparm_query=sys_idIN" + cupaIDList + "&sysparm_first_row=1&sysparm_view=";
              gs.print(cupaURL);
      } else {

              gs.print("No matches found in the Catalog UI Policy Actions table");
      }
}

Additional information

The ServiceNow Community contains several discussions about this Service Catalog issue:

General information about Service Catalog variables and UI policies is available in the product documentation: