OBLYTECH Logo
OBLYTECH Logo

Catalog Item Scripting, UI Policies and Debugging

Two mechanisms shape a catalog item’s form. Client scripts run JavaScript against the order form, and UI policies change whether a variable is shown, required or read-only when a condition holds. When a variable acts unexpectedly, the debugging tools show which script or policy changed it, where load time goes, and whether the requester meets the item’s criteria.

Choosing between a UI policy and a client script

Both act before the requester submits. A UI policy suits a condition that sets field states, such as revealing a follow-up question, making an answer required or locking a value. A client script suits logic such as validating a submission or adding something to the cart. A UI policy handles the simpler show, require and lock states. Turning on Run scripts in a policy exposes the Execute if true and Execute if false fields, which you need for any effect beyond read-only, mandatory or visible. For the platform-wide version of these rules, see the UI policy explainer. For the same two mechanisms outside the service catalog, see client scripts and UI policies outside the service catalog.

Building catalog client scripts

Setup and targets

Create scripts under All > Service Catalog > Catalog Administration > Catalog Client Scripts, then select New. The role needed is admin. Under Applies to, choose Variable Set to attach the script to a variable set instead of a single catalog item. The target is picked through a reference field, because an instance can hold many catalog items. Tick Active to run the script; clear the check box to disable it.

When the script fires

Catalog client scripts run when a requester orders the item, and they can also run while variables or variable sets are displayed during the request. For the platform-wide version, see the client script explainer.

Setting Effect
Type The trigger, such as onLoad, onSubmit or onChange
UI Type The interface. The choices differ between the client script form and the Catalog Builder form, so check the list on your instance
Applies on a Catalog Item view Runs inside the order screen, for the requester
Applies on Requested Items and Catalog Tasks Runs on fulfiller forms after the request
Applies on the Target Record Supports records that record producers create on task-extended tables

An onChange script is tied to one named variable rather than a field, and unnamed variables do not appear in its picker.

Variables and priority

Read a value with g_form.getValue(‘variable_name’). On a Requested Item or Catalog Task form, a table field that shares the variable’s name is matched first, so address the variable as variables followed by its name. For example, g_form.setValue(‘variables.replacement’, ‘false’) sets the variable named replacement. A list collector variable can be refreshed with g_form.refreshSlushbucket(fieldName).

Mandatory outranks ReadOnly and Display. An empty mandatory variable ignores hide or read-only instructions, and a container holding one cannot be hidden. Scripts also run for items placed in a wizard. Scripts run in the browser rather than on the server, which lets them control what the requester submits before it reaches the server.

Building catalog UI policies

Conditions and timing

Create policies under All > Service Catalog > Catalog Administration > Catalog UI Policies, then New. The Global and Inherit fields are not used for the service catalog. A catalog UI policy applies to one catalog item, or to any item that uses a particular variable set. Conditions draw on the item’s named variables. A variable must be visible on the form for the condition to be tested, even when another policy hides or locks it, and a condition can reference variables defined on that item or set, nothing else. Give variables names before you write a condition, since unnamed variables do not appear in the list of available variables. Variables inside a variable set appear in the policy form as variable_set_name » variable_name.

On load runs the policy when the form loads; untick it so the policy runs when the form changes. Reverse if false undoes the effect when the condition stops holding. Order sets the sequence, lowest first, and it also applies in the Service Portal. Catalog UI policies also apply to catalog items shown in a service catalog wizard, so the same conditions hold there. A typical case: when a department question is answered with Department, a follow-up question for the department name becomes mandatory.

Actions and their limits

Action Choices Limits
Mandatory Leave alone, True, False Not for Break, Container Split, Container End, UI Macro, UI Macro with Label, Label or UI Page
Visible Leave alone, True, False Not for Break, Container Split or Container End
Read Only Leave alone, True, False Same exclusions as Mandatory
Value action Leave alone, Set value, Clear value Set value does not work on attachment or masked variables; use Clear value

An action on a variable set applies to the whole set, including each row of a multi-row set. When two actions hit the same variable, the lower order value takes effect. Catalog item policies take precedence over variable set policies by default, and the system property glide.sc.ui_policy.variable_set_run_first changes that order.

Debugging a catalog item

The Debugging Service Catalog area groups tools for user criteria, UI customizations, actions on variables, performance diagnostics, variable debugging and the item diagnostic report. The catalog item overview covers how items are built. A sensible order is the logger first, to see the sequence of actions, then the watcher for one variable, then the performance and access checks. For scripts outside the catalog, the script debugger explainer covers the wider tool.

Trace actions with the variable action logger

Enable it at All > Service Catalog > Catalog Administration > Enable Variable Action Logger. Then open Service Catalog > Catalog Definitions > Maintain Items, select the item, click Try it, right-click the catalog page header and choose Show Variable Action Logger. The output groups actions under UI policies, client scripts and data lookups, with nested numbering such as 1.2.1 for an action triggered from step 1.2.

The logger runs on the client side. It stores nothing in the database and shows output while the form stays open, so export to CSV or print before you close the page. Roles that can use it are admin, catalog_admin, catalog_manager and catalog_editor. The manager and editor roles apply when you are assigned to that catalog.

Watch a single variable

Turn on the JavaScript Log and Field Watcher in the Developer tab of System Settings. Then right-click a variable label on the catalog form and choose Watch Variable. The Variable Watcher tab can filter by Catalog Client Script, Data lookup or Catalog UI Policy, and it also reports client-side scripting errors. Watch one variable at a time. Roles that can use the watcher are admin and catalog_admin.

Measure load cost with the SQL debugger

Enable the variable SQL debugger at Service Catalog > Catalog Variables > Enable Variable SQL Debugger. It works on catalog items and record producers. It stays active after System Diagnostics > Session Debug > Disable All, so switch it off with Disable Variable SQL Debugger. The summary shows total variables, SQL queries and load time. Each variable shows processing time and SQL count, sorted by processing time with the slowest first. Container Start, Container End, Container Split and Break variables are excluded.

Check access and the diagnostic report

User Criteria Diagnostics sits under Catalog Administration. Choose a user and an item, then click Diagnose. Roles that can run it are catalog_manager, catalog_admin and admin. A user needs to match at least one Available for criterion and no Not available for criteria. A scripted criterion that calls gs.getUserID() uses the logged-in session, and the pre-defined user_id variable in its Script field can change that. These diagnostics cover user criteria, not access control list rules.

Debug UI Customization shows the state of each UI macro on a catalog page. Green means unchanged, red means skipped at the latest upgrade, orange means customized after the latest upgrade, and blue means created by the customer. A customer-created macro needs a data-sn-macro-sys-id attribute on its top element.

The item diagnostic report scores each item, where 0 is ideal and lower is better. Rules cover checkUserCriteriaUsage, checkBalancedContainers, checkDuplicateVariables, checkDOMManipulation, checkLookupVariableRowCount, checkAJAX, checkSelectBoxUnique, checkOrderGuideRuleBaseCount and checkFormatterVariablesUsage. checkAJAX looks for AJAX calls in client scripts, which must be asynchronous, and checkDOMManipulation flags DOM changes that may not stay stable across releases. Duplicate variables are more likely to cause user problems than AJAX calls, which mostly add delay. For a backlog across many items, sort them by diagnostic score and start with the highest scores, since a higher score means more violations against recommended practice.

Frequently asked questions

Why does a variable stay visible after my policy hides it?

Check whether the variable is mandatory and empty. Mandatory outranks hide and read-only, so the hide has no effect until the variable has a value or the mandatory setting is switched off.

Which tool shows what changed a variable?

The variable watcher. Watch the variable and filter by Catalog Client Script, Data lookup or Catalog UI Policy. The action logger gives the wider order of actions across the form.

Does the action logger keep a history?

No. It runs on the client side and stores nothing in the database, so export or print the logs before closing the form if you need a record.

Can a catalog UI policy run inside a wizard?

Yes. Catalog UI policies are supported for catalog items shown in a service catalog wizard.

Does the user criteria check cover ACLs?

No. It covers user criteria alone, so check access control list rules separately.