Use metadata in an email notification

Use metadata to populate information in a forms workflow email notification

You can use the Assign Task step to create and assign tasks to a user or group. When a task is assigned to a user or group, an email notification is sent to the defined user or to each member of the defined group. A typical email notification contains link of the assigned task and information related to the task.

You can use metadata in an email template to dynamically populate information in an email notification. For example, the value of the title, description, due date, priority, workflow, and last date in the following email notification is selected dynamically at the runtime (when an email notification is generated).

Metadata is stored in key-value pairs. You can specify the key in the email template and the key is replaced with a value at the runtime (when an email notification is generated). For example, in the below code sample, "$ {workitem_title} " is a key. It is replaced with value “Loan-Request” at the runtime.

Using system generated metadata in an email notification

An AEM Forms application provides several metadata variables (key-value pairs) out of the box. You can use these variables in an email template. The value of the variable is based on the associated forms application. The following table lists all the metadata variables available out of the box:

Key

Description

workitem_title

Title of the associated forms application.

workitem_url

URL to access the associated forms application.

workitem_description

Description of the associated forms application.

workitem_priority

Priority specified for the associated forms application.

workitem_due_date

Last date to act on the associated forms application.

workitem_workflow

Name of the workflow associated with the forms application.

workitem_assign_timestamp

Date and time when the workflow item was assigned to the present assignee.

workitem_assignee

Name of the present assignee.

host_prefix

URL of the author server. For example, http://10.41.42.66:4502

publish_prefix

URL of the publish server. For example, http://10.41.42.66:4503

Using custom metadata in an email notification

You can also use custom metadata in an email notification. Custom metadata contains information in addition to system-generated metadata. For example, policy details retrieved from a database. You can use an ECMAScript or OSGi bundle to add custom metadata in crx-repository:

Use ECMAScript to add custom metadata

ECMAScript is a scripting language. It is used for client-side scripting and server applications. Perform the following steps to use ECMAScript to add custom metadata for an email template:

Log in to CRX DE with an administrative account. The URL is http://[server]:[port]/crx/de/index.jsp

Navigate to /apps/fd/dashboard/scripts/metadataScripts. Create a file with extension .ecma. For example, usermetadata.ecma

If the above-mentioned path does not exist, create it.

Add code to the .ecma file that has the logic to generate custom metadata in key-value pairs. For example, the following ECMAScript code generates custom metadata for an insurance policy:

Specify the title of the script. For example, custom metadata for the policy holder. The specified value is displayed in the assign task step.

Use an OSGi bundle and Java interface to add custom metadata

You can use the WorkitemUserMetadataService Java interface to add custom metadata for email templates. You can create an OSGi bundle that uses the WorkitemUserMetadataService Java interface and deploy it to the AEM Forms server. It makes the metadata available for selection in the Assign Task step.

To create an OSGi bundle with Java interface, add AEM Forms Client SDK jar and granite jar files as external dependencies to the OSGi bundle project. You can use any Java IDE to create an OSGi bundle. The following procedure provides steps to use Eclipse to create an OSGi bundle:

Open Eclipse IDE. Navigate to File > New Project.

On the Select a wizard screen, select Maven Project, and click Next.

On the New Maven project, keep defaults, and click Next. Select an archetype and click Next. For example, maven-archetype-quickstart. Specify Group Id, Artifact Id, version, and package for the project, and click Finish. The project is created.

Open the pom.xml file for editing and replace all the contents of the file with the following: