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:

KeyDescription
workitem_titleTitle of the associated forms application.
workitem_urlURL to access the associated forms application.
workitem_descriptionDescription of the associated forms application.
workitem_priorityPriority specified for the associated forms application.
workitem_due_dateLast date to act on the associated forms application.
workitem_workflowName of the workflow associated with the forms application.
workitem_assign_timestampDate and time when the workflow item was assigned to the present assignee.
workitem_assigneeName of the present assignee.
host_prefixURL of the author server. For example, https://10.41.42.66:4502
publish_prefixURL of the publish server. For example, https://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:

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

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

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

    function getUserMetaData()  {
        //Commented lines below provide an overview on how to set user metadata in map and return it.
        var HashMap = Packages.java.util.HashMap;
        var valuesMap = new HashMap();
        valuesMap.put("policyNumber", "2017568972695");
        valuesMap.put("policyHolder", "Adobe Systems");
    
        return valuesMap;
    }
    
  4. Click Save All. Now, the script is available for selection in AEM workflow model.

    assigntask-metadata

  5. (Optional) Specify the title of the script:

    If you do not specify the title, the Custom Metadata field displays the complete path of the ECMAScript file. Perform the following steps to specify a meaningful title for the script:

    1. Expand the script node, right-click the jcr:content node, and click Mixins.

    2. Type mix:title in Edit Mixins dialog and click +.

    3. Add a property with the following values.

      Namejcr:title
      TypeString
      ValueSpecify 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:

  1. Open Eclipse IDE. Navigate to File > New Project.

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

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

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

  5. Add source code that uses WorkitemUserMetadataService Java interface to add custom metadata for email templates. A sample code is listed below:

    package com.aem.impl;
    
    import com.adobe.fd.workspace.service.external.WorkitemUserMetadataService;
    import org.apache.felix.scr.annotations.Component;
    import org.apache.felix.scr.annotations.Properties;
    import org.apache.felix.scr.annotations.Property;
    import org.apache.felix.scr.annotations.Service;
    import org.osgi.framework.Constants;
    
    import java.util.HashMap;
    import java.util.Map;
    
    @Component
    @Service
    @Properties({
            @Property(name = Constants.SERVICE_DESCRIPTION, value = "A sample implementation of a user metadata service."),
            @Property(name = WorkitemUserMetadataService.SERVICE_PROPERTY_LABEL, value = "Default User Metadata Service")})
    
    public class WorkitemUserMetadataServiceImpl
      implements WorkitemUserMetadataService
    {
      public WorkitemUserMetadataServiceImpl() {}
    
      public Map<String, String> getUserMetadataMap()
      {
        HashMap<String, String> metadataMap = null;
        metadataMap = new HashMap();
        metadataMap.put("test_metadata", "tested-interface implementation");
        return metadataMap;
      }
    }
    
  6. Open a command prompt and navigate to the directory containing the OSGi bundle project. Use the following command to create the OSGi bundle:

    mvn clean install

  7. Upload the bundle to an AEM Forms server. You can use AEM Package Manager to import the bundle to AEM Forms server.

After the bundle is imported, you can select the metadata in the Assign Task step and use it an email template.

Experience Manager