Scripted templates
-
- UpdatedJan 30, 2025
- 2 minutes to read
- Yokohama
- Form Administration
You can apply an active template to a record using JavaScript.
Apply a template to current
To apply a template, use the applyTemplate method.Apply a template to a GlideRecord
To apply the template to a record other than current, change current to a GlideRecord variable. When using a GlideRecord variable, you may need to initialize it after declaring the variable.
Apply a template from a UI action
The following script demonstrates a possible customization to the Create Change UI action on the Problem form. After you add this script to the UI action, a user can select the UI action to create a change record with information from both the problem record and the change template.Script a template with child templates
When using applyTemplate with a template that has one or more child templates, the system creates the parent record before applying the child templates. This behavior ensures that any references or dot-walked fields from the child record to the parent have a valid target.
For example, if a template for the Change Request table has a child template for the Change Task table, applying the Change Request template inserts a Change Request record into the database. It assigns this record as the Change request for the Change Task record, then applies the child template to the Change Task record.
Apply a template using a sys_id instead of a name
On this page
Related Content
- Create a template using the Template form
Create a template record for any table to populate certain fields automatically.
- Create templates for related task records
Administrators can create a template for a Task table record that also creates one or more related records in the child Task table.
- Create a template by saving a form
Save a populated form as a template.
- Create records based on a template
You can create and schedule a scheduled job to create records based on a template. For example, you can regularly create a populated task record to perform a weekly backup.
- Create a module for a template
You can create a module to open a form with pre-populated template data.
- Template bar
Use the template bar to apply, edit, and create templates.
- Toggle the template bar
The template bar appears at the bottom of forms. It provides shortcuts to apply, edit, and create templates.