Workflow notification in 5.6

Hello

I create my own workflow which send a notification to validate a document. But an error occur and the mail isn't send :

2013-03-07 11:00:18,027 ERROR [freemarker.runtime]

Expected hash. WorkflowVariables["valideur_dsi"] evaluated instead to freemarker.template.SimpleSequence on line 1, column 14 in mail_valide_doc_dsi.
The problematic instruction:
----------
==> ${WorkflowVariables["valideur_dsi"].firstName} [on line 1, column 12 in mail_valide_doc_dsi]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateException: Expected hash. WorkflowVariables["valideur_dsi"] evaluated instead to freemarker.template.SimpleSequence on line 1, column 14 in mail_valide_doc_dsi.
        at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:135)
        at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
        at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
        at freemarker.core.Expression.getStringValue(Expression.java:93)
        at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
        at freemarker.core.Environment.visit(Environment.java:208)
        at freemarker.core.MixedContent.accept(MixedContent.java:92)
        at freemarker.core.Environment.visit(Environment.java:208)
        at freemarker.core.Environment.process(Environment.java:188)
        at freemarker.template.Template.process(Template.java:232)
        at org.nuxeo.ecm.platform.rendering.template.FreemarkerRenderingEngine.process(FreemarkerRenderingEngine.java:63)
        at org.nuxeo.ecm.platform.rendering.impl.RenderingServiceImpl.process(RenderingServiceImpl.java:91)
        at org.nuxeo.ecm.platform.ec.notification.email.EmailHelper.sendmail(EmailHelper.java:156)
        at org.nuxeo.ecm.platform.ec.notification.NotificationEventListener.sendNotification(NotificationEventListener.java:367)
        at org.nuxeo.ecm.platform.ec.notification.NotificationEventListener.sendNotificationSignalForUser(NotificationEventListener.java:270)
        at org.nuxeo.ecm.platform.ec.notification.NotificationEventListener.handleNotifications(NotificationEventListener.java:184)
        at org.nuxeo.ecm.platform.ec.notification.NotificationEventListener.handleEvent(NotificationEventListener.java:107)
        at org.nuxeo.ecm.core.event.impl.AsyncEventExecutor$ListenerWork.work(AsyncEventExecutor.java:186)
        at org.nuxeo.ecm.core.work.AbstractWork.run(AbstractWork.java:150)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
2013-03-07 11:00:18,037 ERROR [org.nuxeo.ecm.platform.ec.notification.NotificationEventListener] An error occurred while trying to send user notification
org.nuxeo.ecm.core.api.ClientException: Failed to send notification email

I the mail template, I write :

<p>Bonjour ${WorkflowVariables["valideur_dsi"].firstName}</p>
<br /> 
L'utilisateur ${workflowInitiator} souhaite faire relire ce document :<br /> 
<br /> 
Titre : ${Document['dc:title']}<br /> 
<br /> 
Description : ${Document['dc:description']}<br /> 
<br /> 
Date de création : ${Document['dc:created']}<br /> 
<br /> 
Lien vers le document : <a href="${docUrl}">${Document['dc:title']}</a><br />\ |
<br/>
Merci d'avance

But there must be an error in the variables …

Someone to help me ? Thanks in advance !

0 votes

2 answers

941 views

ANSWER



Hi,

You can use Fn.getPrincipal("userName") to get the infos:

${Fn.getPrincipal("userName").firstName}

If you can't hard-code the name, then you must use an intermediate variable to store the information. In an automation chain in the Studio for example, you'll have something like this:

[...previous actions...]
Execution Context > Set Context Variable
    name:  zeUser
    value: @{WorkflowVariables["valideur_dsi"]}
Notification  Send E-Mail
[...next actions...]

In the template of the eMail, you use Fn.getPrincipal((zeUser):

Bonjour ${Fn.getPrincipal(zeUser).firstName}  ${Fn.getPrincipal(zeUser).lastName},
...

Thibaud

0 votes



WorkflowVariables[“valideur_dsi”] return the value stored into the Workflow named valideur_dsi => username.

If you want the firstname, you will have to fetch the Profile Object of the user.

I have no easy in my head now to help you to fetch that. My ideas would be to store also the firstname and last name by automation, but that a bit ugly… Maybe someone can help ?

0 votes