Please use docs.servicenow.com for the latest documentation.
This site is for reference purposes only and may not be accurate for the latest ServiceNow version
Client Script Access to Variable Fields on Task Records
| Note: This article applies to Fuji and earlier releases. For more current information, see Support Client APIs at http://docs.servicenow.com
The ServiceNow Wiki is no longer being updated. Visit http://docs.servicenow.com for the latest product documentation.
Variable fields may be accessed via client script on records that are based on the task record. The most obvious use for this is making Service Catalog variables conditionally display and function in the same way as they did when initially creating an order when they subsequently appear on Request [sc_request], Requested Item [sc_req_item], and Catalog Task [sc_task] records.
The following API is supported via g_form:
- g_form.setDisplay(name, display)
- g_form.setVisible(name, visibility)
- g_form.setMandatory(name, mandatory)
- g_form.setValue(name, value, display_value)
- g_form.setReadOnly(fieldName, boolean) (beginning with the Calgary release)
To specify that a variable is to be the object of the API call, the name must be prefixed with “variables.”. This is necessary as another field that is not a variable but has the same name may already be present on the form.
For example, if we ordered an Executive Desktop using the out-of-box Service Catalog, we could add a client script to the Request Item [sc_req_item] to disable the display of the “cpu_speed” variable one would create a client script containing:
Hiding Mandatory Variables
To hide a mandatory variable using a script, the script must first set the mandatory property of the variable to false.