Widget option schema
-
- UpdatedAug 1, 2024
- 5 minutes to read
- Xanadu
- Service Portal Designer
Widget instances allow users to uniquely configure each widget they add to a page. Use the option schema to define the parameters for your widget.
Storing instance options
When developing a widget, you can edit the option schema to create parameters for your widget, or you can create a table to store instance options. If you edit the existing option schema, any instance options defined are stored in JSON format in the Additional options, JSON format field in the sp_instance table. The following field types are available:
- String
- Boolean
- Integer
- Reference
- Choice
- Field_list (depends on table)
- Field_name (depends on table)
- Glide_list
To use other field types not supported in the option schema, create an extension table to store your custom widget option schema. Using a table enables you to:
- Add any ServiceNow field type, including fields with advanced customization, to the option schema.
- Define a complex option schema.
- Search and filter instance options.
Using options in a widget
Access options in the widget from both the client script and the server script using the
options global variable. You can access to any option value in your
widget client script or server script using options.optionName
.
Defining default options
Before an option value is set on an instance, it appears as an undefined value when you access that option variable. Use the widget server script to specify default values for your options.
Edit the widget option schema
Widget instances allow users to uniquely configure each widget they add to a page. Edit the option schema to define basic parameters for your widget.
Before you begin
You must have cloned or created a new widget.
Role required: admin or sp_admin
Procedure
Store instance options in a table
Create a table to store widget instance options instead of editing the existing option schema. When using a table as your widget option schema, you can define custom fields using any ServiceNow field type, add filters to fields, and search or query instance options.
Before you begin
Role required: admin or sp_admin
About this task
To define a custom option schema, add fields to an sp_instance extension table, then set your widget to use the extension table as a data source. Using an extension table enables you to:
- Add any ServiceNow field type, including fields with advanced customization, to the option schema.
- Define complex widget options.
- Search and filter instance options.
Procedure
What to do next
Test the option schema by adding the widget to a page in the Service Portal Designer. Click the edit icon on the widget instance to view the instance options. After configuring the widget instance options, view the configuration by navigating to the instance record in the sp_instance extension table.