Issue
Description
This article explains how to set a default value for Image fields on a new form.
There isn't any OOTB way of setting a default value for the Image type field on a form. The default value in the field dictionary's doesn't set the default image for the record. However, a Before insert Business Rule can be written to populate the field.
The images are stored in the sys_attachment table. In the sys_attachment table, the "File name" is the name of the field, and "Table name" is ZZ_YY plus the name of the table (e.g., ZZ_YYincident). "Table sys ID" is the sys_id of the original record.
You need to create a before query Business Rule using the following API method:
GlideSysAttachment.copy(String sourceTable, String sourceID, String targetTable, String targetID)
Copies attachments from the source record to the target record.
Name | Type | Description |
---|---|---|
sourceTable | String | Name of the table with the attachments to be copied. |
sourceID | String | The source table's sysID. |
targetTable | String | Name of the table to have the attachments added. |
targetID | String | The target table's sysID. |
Example:
If you want to populate the image field on a new Incident form, use the following format.
GlideSysAttachment.copy("ZZ_YYincident", "<Table sys ID>", "ZZ_YYincident", current.sys_id);
Procedure
- If there is already an image added on an existing record (e.g., Incident), ignore step 2
- Add an image to the image field on the form
- Go to sys_attachment.LIST
- Find the recent record for the field (record of the image that you want to use as a default)
- Copy the sys ID from "Table sys ID" column
- Create a Before Insert Business Rule on the Table as follows:
When: before - Insert
Active : <checked>
Advanced: <checked>
**script:
GlideSysAttachment.copy("ZZ_YYincident", "<Table sys ID>", "ZZ_YYincident", current.sys_id); - Result: Image field will be auto-populated when a new record is created in the table.
Note: The steps provided above are for Incident table. You can use the steps for other tables as well.
Applicable Versions
All releases