Notifications

236 views

Description

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.

Parameter(s):
NameTypeDescription
sourceTableStringName of the table with the attachments to be copied.
sourceIDStringThe source table's sysID.
targetTableStringName of the table to have the attachments added.
targetIDStringThe 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


  1. If there is already an image added on an existing record (e.g., Incident), ignore step 2
  2. Add an image to the image field on the form
  3. Go to sys_attachment.LIST
  4. Find the recent record for the field (record of the image that you want to use as a default)
  5. Copy the sys ID from "Table sys ID" column
  6. 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);

  7. 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

Additional Information


API Documentation

Product Documentation

Community article

Article Information

Last Updated:2019-08-02 20:58:07
Published:2018-12-13