Workflow Notification Template Variables
Liferay 7.3+
Some variables are auto-injected into the workflow notification context. These are handy to use in your workflow notification templates.
Normally in Freemarker, you must declare variables explicitly:
<#assign variableName = "Variable Name" />
Injected variables are already declared and can be used directly in the template.
${variableName}
To use these variables, you must know which are available in your workflow notification context. The variables available change depending on the workflow definition details and the asset in the workflow. The method presented here shows you how to get the list of variables for your specific context, so you don’t have to do any guesswork.
Discovering the Workflow Notification Template Variables
Enable DEBUG level logging for the TemplateNotificationMessageGenerator
class to display the variables available in your workflow notification context:
-
Go to Control Panel → Configuration → Server Administration.
-
Click the Log Levels tab.
-
Add a Log Level with this configuration:
- Logger Name:
com.liferay.portal.workflow.kaleo.runtime.internal.notification.TemplateNotificationMessageGenerator
- Log Level:
DEBUG
- Logger Name:
-
Activate a workflow definition (e.g., the Single Approver definition) on an asset (e.g., Blogs Entry).
-
Submit a test entry and log messages appear that reveal the workflow available notification template variables in the context of your workflow.
For example, the Single Approver workflow shows these variables on initial submission of an asset:
2020-03-30 14:21:42.089 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] saxReaderUtil (class com.sun.proxy.$Proxy447)
2020-03-30 14:21:42.097 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] getterUtil (class com.liferay.portal.kernel.util.GetterUtil_IW)
2020-03-30 14:21:42.098 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] portalPermission (class com.liferay.portal.service.permission.PortalPermissionImpl)
2020-03-30 14:21:42.098 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] entryClassPK (class java.lang.String)
2020-03-30 14:21:42.098 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] layoutPermission (class com.liferay.portal.service.permission.LayoutPermissionImpl)
2020-03-30 14:21:42.098 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] expandoTableLocalService (class com.sun.proxy.$Proxy43)
2020-03-30 14:21:42.098 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] localeUtil (class com.liferay.portal.kernel.util.LocaleUtil)
2020-03-30 14:21:42.099 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] groupId (class java.lang.String)
2020-03-30 14:21:42.099 DEBUG [liferay/kaleo_graph_walker-2][TemplateNotificationMessageGenerator:94] portalUtil (class com.liferay.portal.util.PortalImpl)
...
The snippet of output above shows that saxReaderUtil
, getterUtil
, portalPermission
, entryClassPK
, layoutPermission
, expandoTableLocalService
, localeUtil
, groupId
, and portalUtil
are available in the context that caused these messages to be printed in the log.
Using the Workflow Notification Template Variables
The contextually injected notification variables can be categorized into two main types:
-
Value variables provide a single value. If a variable provides a single value, you can use it to display that value in the notification, or you can pass it as a parameter to an operation that retrieves some other useful information to be displayed in the notification message.
Example: The Single Approver definition provides this notification in a FreeMarker template:
${userName} sent you a ${entryType} for review in the workflow.
The
userName
andentryType
provide values, so the notification might render like this:Joe Bloggs sent you a Blogs Entry for review in the workflow.
The value type variables can also be checked for content. The Single Approver definition also contains this notification template:
Your submission was reviewed<#if taskComments?has_content> and the reviewer applied the following ${taskComments}</#if>.
If the reviewer provided task comments, they’re shown. Otherwise, the notification recipient only sees
Your submission was reviewed
-
Operation variables expose a Liferay DXP Java class, so you can access its operations in the notification template. For these variables, you must familiarize yourself with the class’s Javadoc or look into the source code to understand its operations.
Example: This FreeMarker gets you the current date, using the default locale, in a specific pattern (Month/Day/Year, Hour:Minute):
${dateUtil.getCurrentDate("MM/dd/yyyy, HH:mm", localeUtil.getDefault())}`
Understanding the Workflow Notification Template Variables
These are the variables logged when you enable the Single Approver Definition for Blogs Entries, then submit a new entry for publication:
Variable Name | Value | Operation | Description or Link |
---|---|---|---|
${saxReaderUtil} | ✔ | SaxReaderUtil | |
${getterUtil} | ✔ | GetterUtil | |
${portalPermission} | ✔ | PortalPermission | |
${entryClassPK} | ✔ | The primary key of the Entry Class | |
${layoutPermission} | ✔ | LayoutPermission | |
1$1 | ✔ | ExpandoTableLocalService | |
${localeUtil} | ✔ | LocaleUtil | |
${groupId} | ✔ | The ID of the group | |
${portalUtil} | ✔ | PortalUtil | |
${validator} | ✔ | Validator | |
${dateUtil} | ✔ | DateUtil | |
${serviceLocator} | ✔ | ServiceLocator | |
${serviceContext} | ✔ | ServiceContext | |
${jsonFactoryUtil} | ✔ | JSONFactoryUtil | |
${stringUtil} | ✔ | StringUtil | |
${freeMarkerPortletPreferences} | ✔ | TemplatePortletPreferences | |
${dateFormats} | ✔ | FastDateFormatFactory | |
${dateFormatFactory} | ✔ | DateFormatFactory | |
${userPortraitURL} | ✔ | Applies only to Blogs Entries; returns the URL to the User’s portrait. | |
${portal} | ✔ | Portal | |
${commonPermission} | ✔ | CommonPermission | |
${userURL} | ✔ | Applies only to Blogs Entries; returns the URL to a logged in User’s profile page. See UserImpl#getDisplayURL. | |
${expandoValueLocalService} | ✔ | ExpandoValueLocalService | |
${entryType} | ✔ | The type of entry in the workflow (e.g., Blogs Entry) | |
${organizationPermission} | ✔ | OrganizationPermission | |
${passwordPolicyPermission} | ✔ | PasswordPolicyPermission | |
${expandoColumnLocalService} | ✔ | ExpandoColumnLocalService | |
${taskComments} | ✔ | The comments, if any, left by the reviewer | |
${staticFieldGetter} | ✔ | StaticFieldGetter | |
${htmlUtil} | ✔ | HtmlUtil | |
${languageUtil} | ✔ | LanguageUtil | |
${enumUtil} | ✔ | Returns the result of beansWrapper.getEnumModels() ; for Accessing Enums | |
${windowStateFactory} | ✔ | WindowStateFactory | |
${companyId} | ✔ | The ID of the portal’s Company/Virtual Instance | |
${unicodeFormatter} | ✔ | UnicodeFormatter | |
${propsUtil} | ✔ | PropsUtil | |
${browserSniffer} | ✔ | BrowserSniffer | |
${portletProviderAction} | ✔ | Returns the outcome of the PortletProvider#Action call | |
${taskName} | ✔ | The name of the task the notification is in | |
${httpUtil} | ✔ | HttpUtil | |
${portletURLFactory} | ✔ | PortletURLFactory | |
${imageToken} | ✔ | An image token from WebServerServletToken.getToken(long imageId); is deprecated and will be removed | |
${groupPermission} | ✔ | GroupPermission | |
${timeZoneUtil} | ✔ | TimeZoneUtil | |
${unicodeLanguageUtil} | ✔ | UnicodeLanguageUtil | |
${expandoRowLocalService} | ✔ | ExpandoRowLocalService | |
${auditRouterUtil} | ✔ | AuditRouterUtil | |
${kaleoTaskInstanceToken} | ✔ | See the documentation on workflow scripting | |
${accountPermission} | ✔ | AccountPermission | |
${httpUtilUnsafe} | ✔ | Like ${httpUtil} , an instance of Http, but can be used to access the local network | |
${workflowTaskAssignees} | ✔ | See the documentation on workflow scripting | |
${random} | ✔ | A Java utility for generating Random numbers; is deprecated and will be removed in the future | |
${rolePermission} | ✔ | RolePermission | |
${portletPermission} | ✔ | PortletPermission | |
${paramUtil} | ✔ | ParamUtil | |
${locationPermission} | ✔ | Returns the outcome of OrganizationPermissionUtil.getOrganizationPermission() | |
${calendarFactory} | ✔ | CalendarFactory | |
${webServerToken} | ✔ | An image token from WebServerServletToken.getToken(long imageId) | |
${sessionClicks} | ✔ | SessionClicks | |
${userPermission} | ✔ | UserPermission | |
${entryClassName} | ✔ | ||
${userGroupPermission} | ✔ | UserGroupPermission | |
${arrayUtil} | ✔ | ArrayUtil | |
${userName} | ✔ | The User Name of the last user to intervene in the workflow | |
${userId} | ✔ | The User ID of the last user to intervene in the workflow. See the Workflow Scripting article to understand the logic. | |
${prefsPropsUtil} | ✔ | PrefsPropsUtil | |
${url} | ✔ | a URL for certain content types that are displayed on a page (e.g., Blogs Entries, Message Boards Messages, and Wiki Pages | |
${kaleoInstanceToken} | ✔ | See the Workflow Scripting article. | |
${utilLocator} | ✔ | UtilLocator | |
${objectUtil} | ✔ | Returns a new LiferayObjectConstructor() | |
${urlCodec} | ✔ | URLCodec | |
${portletModeFactory} | ✔ | PortletModeFactory | |
${imageToolUtil} | ✔ | ImageToolUtil | |
${auditMessageFactoryUtil} | ✔ | AuditMessageFactoryUtil | |
${staticUtil} | ✔ | Returns the result of beansWrapper.getStaticModels() ; for Accessing static methods |