OBLYTECH Logo
OBLYTECH Logo

Catalog Client Scripts for Item Forms

A ServiceNow catalog client script controls item form behavior in the browser. Use it to read or change variable values, adjust visibility and mandatory status, or validate submission. Choose the catalog item or variable set, select when the script runs, and enable the requester or fulfiller views where that behavior belongs.

Define the behavior before creating the script

Start with a sentence describing the expected result: when a requester changes a question, another variable should become required. Separate the trigger, the affected variable, and the intended form view. This gives you something specific to test instead of treating a script that saves successfully as a completed change.

Catalog client scripts attach to a catalog item or a variable set rather than a table such as Incident. Choose an item when the requirement belongs to that item. Consider a variable set when the behavior belongs with those shared variables.

Check that the variables have names. A variable without a name cannot be accessed through a catalog client script and does not appear among the available variables. An onChange script is associated with a particular variable; its selection list is populated from named variables on the chosen item or variable set.

Write down the variable names beside their visible questions. During review, compare the names used by the script with the variables on the selected item. For broader preparation, use the guide to the ServiceNow variable table. Keep the acceptance condition focused on what the person completing the form should experience.

Create the ServiceNow catalog client script record

The creation action in Catalog Administration requires the admin role. Navigate to All > Service Catalog > Catalog Administration > Catalog Client Scripts, then select New. Use the following sequence to keep the record’s scope and behavior aligned.

  1. Enter a unique Name that describes the behavior and the item or variable set it serves.
  2. Set Applies to to A Catalog Item or A Variable Set. This selection determines which reference field becomes available.
  3. Select the intended Catalog item or Variable set. Confirm the reference before choosing the variable for a change event.
  4. Choose Type to determine when the script runs. Use onLoad for loading behavior, onChange for a variable change, or onSubmit for submission behavior.
  5. Enter the logic in Script and set Active according to whether the script should be enabled.
  6. Review UI Type and the view check boxes before selecting Submit.

Use a name that explains the decision, such as requiring a replacement reason for a replacement request. Avoid a name that merely repeats the event type. A reviewer should be able to connect the record to a requirement without opening the script and reconstructing its purpose.

Field labels can differ between ServiceNow releases, so check them on your instance. The administration form’s UI Type offers desktop and Classic Mobile coverage, while Catalog Builder offers Desktop, Mobile or Service Portal, or all.

Select the form views that need the behavior

The requester order screen and the later fulfiller forms have separate applicability controls. Decide where the requirement applies rather than enabling several views simply because they are available. A question that guides ordering may need different treatment when someone reviews the submitted request.

  • Applies on a Catalog Item view covers the item shown within the service catalog order screen in the requester view.
  • Applies on Requested Items covers the Requested Item form after the item has been requested, in the fulfiller view.
  • Applies on Catalog Tasks covers the item’s Catalog Task form in the fulfiller view.
  • Applies on the Target Record supports a record created for a task-extended table through a record producer.

Build a small test list with one row per intended view. For each row, record the starting values, the action to perform, and the expected variable state. Include a view where the behavior should not apply. This makes an accidental expansion of scope easier to detect.

Keep the form test separate from the assessment of what happens during fulfillment. The guide to request fulfillment flows and requested item states addresses that neighboring concern. Here, the immediate question is whether the selected form presents and validates its variables as intended.

Resolve mandatory, visibility, and read-only conflicts

Mandatory status has higher priority than read-only or display settings in g_form behavior. If a mandatory variable has no value, hiding it or making it read-only does not work. If a hidden or read-only variable is then made mandatory, it becomes visible or editable.

The same priority affects variable sets and containers. A container or variable set containing an empty mandatory variable cannot be hidden. When a whole group refuses to disappear, inspect the required variables inside it before changing the display logic again.

Consider a replacement-reason question that should disappear when no replacement is needed. Plan the unwanted state as carefully as the required state: the question should no longer be mandatory before you expect it to remain hidden. Test with the reason empty, then with a value already entered. These starting conditions exercise different parts of the requirement.

For a review of related form controls, use catalog item scripting, UI policies, and debugging. If your team needs help defining these rules across an implementation, discuss the item scope, form views, and acceptance tests through Oblytech’s ServiceNow implementation service. Bring the expected behavior and a reproducible failing case to that discussion.

Use the Catalog Builder creation route

Creating a client script in Catalog Builder requires admin and catalog_builder_developer. Navigate to All > Service Catalog > Catalog Builder. On Dashboard, select Create a new catalog item, review the starting information, and select Continue. Choose a template and select Use this item template.

Complete the required steps until you reach client script creation, then select New. In the Catalog client script form, use Actions to enter the script, give it a unique name, set its active state, and select the script type. When the type is onChange, Select question becomes available for choosing the required question.

Continue to Settings to specify the scenarios where the script applies. Settings also contains UI Type and Order, with Order represented as a sequence number. Review these alongside the requester and fulfiller scenarios, then select Add script.

Prepare the behavior and test cases before entering this flow. That leaves fewer decisions to resolve while moving through the item steps. The guide to building and editing items in Catalog Builder covers the surrounding item work.

Check the complete behavior before handing it over

Test a fresh form load, a relevant variable change, and submission where those events are part of your requirement. Include a blank answer and an answer that satisfies the rule. Then reverse the triggering choice and check that the form reaches the expected state again.

If nothing happens, review the selected item or variable set, variable names, Active, Type, UI Type, and applicability settings before rewriting the logic. If the behavior appears in the wrong place, compare the view you tested with the checked scenarios. Change one suspected cause at a time and repeat the same test. Note the original settings and the observed result before changing anything else. If two changes are needed, test them separately before checking their combined effect on the item.

Record the final configuration with the acceptance result: which item it affects, which event starts it, which variables it changes, and which views were tested. Include the case that previously failed. This gives the next maintainer a concrete way to judge whether a later change preserves the intended behavior.

Four catalog client script questions: wizards, list collectors and record producers

Can a catalog client script work with an item in a wizard?

Yes. Catalog client scripts can be used for catalog items included in a wizard. Include that presentation in your test plan when it is part of the item journey.

How can a list collector variable be refreshed?

The g_form.refreshSlushbucket(fieldName) API updates a list collector variable. Identify the intended variable before adding a refresh operation, then check the resulting list during testing.

What if a table field and a variable share a name?

In a standard client script on a Requested Item or Catalog Task form, the table field is matched if both are present. Address the variable explicitly with variables.variable name, such as variables.replacement.

Can record producer variables be manipulated on the resulting record?

Record producer variables shown through a variable editor can be manipulated with standard client script methods, including setDisplay, setMandatory, setValue, and getValue. Identify the variable editor context when planning that work.