1 Reply Latest reply on Jun 12, 2008 4:39 AM by Tom Baeyens

    Variables in Mail Templates

    Matthias Grossmann Newbie

      Hi everyone

      I have tuned up a little the usage of variables in Mail Templates.

      usually when you want to use a variable like that

      <mail-templates>
      
       <variable name="defaultSubject" value="Mail" />
      
       <mail-template name='default'>
       <actors>#{taskInstance.actorId}</actors>
       <subject>#{defaultSubject}</subject>
       <text><![CDATA[Mail von Geppi:
       #{mailMessage}]]>
       </text>
       </mail-template>
      


      the variable is evaluated correctly and the value of Subject is set to "Mail"

      but if you want to use variable references within the variables like this

      <mail-templates>
      
       <variable name="defaultSubject" value="[#{processDefinition.name} #{processInstance.id}] generated Mail" />
      
       <mail-template name='default'>
       <actors>#{taskInstance.actorId}</actors>
       <subject>#{defaultSubject}</subject>
       <text><![CDATA[Mail von Geppi:
       #{mailMessage}]]>
       </text>
       </mail-template>
      


      the value within the variable is not evaluated.
      So i added a loop which evaluates the variable value until all references are solved.

      In class org.jbpm.mail.Mail:




      public String getSubject() {
       if (subject==null) return null;
       Object parsedValue = null;
       String ret = subject;
       do {
       ret = evaluate(ret);
       ret = JbpmExpressionEvaluator.translateExpressionToDollars(ret);
       parsedValue = new ExpressionEvaluatorImpl().parseExpressionString(ret);
       } while (!(parsedValue instanceof String));
      
       return ret;
       }
      
       public String getText() {
       if (text==null) return null;
       Object parsedValue = null;
       String ret = text;
       do {
       ret = evaluate(ret);
       ret = JbpmExpressionEvaluator.translateExpressionToDollars(ret);
       parsedValue = new ExpressionEvaluatorImpl().parseExpressionString(ret);
       } while (!(parsedValue instanceof String));
      
       return ret;
       }
      


      i will post a Jira Patch for this too

      regards

      Matthias

        • 1. Re: Variables in Mail Templates
          Tom Baeyens Master

          my first thought would be that looping is not good. i would opt for a solution that makes it clear when expressions are resolved and when not.

          e.g. introduce a new attribute like:

          <variable name="defaultSubject" value-expr="[#{processDefinition.name} #{processInstance.id}] generated Mail" />


          if you have an eclipse patch file for the latter solution including a test for both attributes (incl one showing that #{sdfsd} is not resolved when using the value), then we can include it quickly. otherwise it will depend on when (if) we have the time to include this improvement.