Clarity

 View Only
  • 1.  gel: dynamic variables containing html

    Posted Jun 13, 2017 12:05 PM

    I need to fill a var (core:set) with rows from a query(variable num of rows)

    Also I want to add html tags(<BR></BR>) between rows in order to be able to send the string by email (gel:email) with format.

     

    I am finding problems creating the string:

    • using concat()  [with escapetText=1 or 0]
      • codeprev.concat(text.concat(codepost))
        • <core:set var="codeprev"> <BR> </core:set>
          • when save; UI BPM-0703: Custom script syntax error at line , column : The element type "BR" must be terminated by the matching end-tag "</BR>".
        • <core:set var="codeprev"> &lt;BR&gt; </core:set>
          • code is displayed in email as escaped but it is not interpreted
    • in the content of core:set
      • <core:set var="var_text" escapeText="0"><br>${text}</br><br>${text}</br></core:set>
        • it works fine but it is not dynamic
      • var inside a foreach
        • <core:forEach>        
                  <core:set value="${slRow.field}" var="text"/>            
                  <core:set var="var_string">${var_string}<BR>${text}</BR></core:set>        
           </core:forEach>
        • tested with different combinations of  escapeText, when displaying the var, it always shows escaped html codes, and just the text from the last row is displayed properly.

                            Example of email

                                  <br>textstring1</br>
                                   textstring2

     

    The main reason for creating a string containing html is that I would like to make persist and use in a later action/step.



  • 2.  Re: gel: dynamic variables containing html

    Posted Jun 19, 2017 04:30 PM

    Hi,

     

    Just get all values "without format" in variables.

    Then send the email with HTML . See an example here: CA PPM: Send HTML email with GEL 



  • 3.  Re: gel: dynamic variables containing html

    Posted Jun 20, 2017 04:02 AM

    Sorry Aurora, but I don't understand what you mean

     

    Do you mean to using core:set without the parameter escapeText?

     

    For setting values I tried with escapeText true and false but theoretically only espaceText=0 (XML)  is required because the default value is 1(Text).

     

    For displaying the variable i use something like that:

    <gel:email ....>
        <![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
        <HTML><HEAD/><BODY>]]>        
        ${var_mystring1}
        <![CDATA[ </BODY></HTML>]]>    
    </gel:email>

     

    To sum up, I want to load a variable in a foreach, add formatting html (frand send this string containing html and text  in a html formatted email. I tried the following in many different ways, and always without success

     

    <core:forEach begin="0" items="${output.rows}" var="..">

           ...

          <core:set var="var_mystring1">  ${var_mystring1} <br>  ${vfield1} </br> </core:set>

     </core:forEach>

     

    BTW, I just discovered that there is also a parameter "encode" which i didn't try.

    <core:set encode="1">  encodes  "<" and ">" as "&lt;" and "&gt;" but also i got it with escapeText, the problem is that from sending email this escaped html was not interpreted.

     

    GEL Tag Library Reference 



  • 4.  Re: gel: dynamic variables containing html

    Posted Jun 20, 2017 11:29 AM

    See a simple exampl of what I mean:

     

    <gel:script
    xmlns:core="jelly:core"
    xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
    xmlns:mail="jelly:email"
    xmlns:sql="jelly:sql"
    xmlns:util="jelly:util">

    <gel:setDataSource dbId="niku"/>

    <!-- get data -->
    <sql:query escapeText="false" var="v_qryresult">     
         <![CDATA[select i.name name
                   from inv_investments i
                   where i.name like '%Test%' ]]>

    </sql:query>
    <core:forEach items="${v_qryresult.rowsByIndex}" var="varRow">
         <core:set value="${varRow[0]}" var="var_mystring1"/>

    <!-- Send HTML email -->
    <gel:email from="luckyuser@dummy.com"
    fromName="Lucky User"
    subject="This is a test email with GEL"
    to="sender@dummy.com">

    <![CDATA[
    <html>
    <body>
    <p> </p>
    <p>Here it is: <b>]]>
    ${var_mystring1}<![CDATA[</b> ....and more text here if you want....</p>
    <p> </p>
    </body>
    </html>
    ]]>

    </gel:email>

    </core:forEach>
    </gel:script>

     

    Result should be:

     

     

     

    So, el HTML formatting.. goes into the email, not before. So, i can make bold your variable.



  • 5.  Re: gel: dynamic variables containing html

    Posted Jun 20, 2017 12:02 PM

    To expand on Aurora's comments.  You could just load your values into an arraylist and loop through them using her CDATA approach to embedding <br> tags.

     

    <gel:script
    xmlns:core="jelly:core"
    xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
    xmlns:mail="jelly:email"
    xmlns:sql="jelly:sql"
    xmlns:util="jelly:util">

         <gel:setDataSource dbId="niku"/>

         <!-- get data -->
         <sql:query escapeText="false" var="v_qryresult">    
              <![CDATA[select i.name name from inv_investments i where i.name like '%Test%' ]]>
         </sql:query>

         <core:new className="java.util.ArrayList" escapeText="false" var="investmentNames" />
         <core:forEach items="${v_qryresult.rowsByIndex}" var="varRow">
              <core:expr value='${investmentNames.add(varRow[0])}' />
         </core:forEach>

         <!-- Send HTML email -->
         <gel:email from="luckyuser@dummy.com"
    fromName="Lucky User"
    subject="This is a test email with GEL"
    to="sender@dummy.com">

              <![CDATA[
    <html>
    <body>
    <p> </p>
    ]]>

              <core:forEach items="${investmentNames}" var="investmentName">
                   <![CDATA[<p>Here it is: <b>]]>${investmentName}<![CDATA[</b> ....and more text here if you want....</p>]]>
              </core:forEach>
              <![CDATA[
    </body>
    </html>
    ]]>

         </gel:email>
    </gel:script>

     

    Haven't tested this but it should look something like this.


    V/r,

    Gene



  • 6.  Re: gel: dynamic variables containing html

    Posted Jun 21, 2017 06:17 AM

    Yes, a foreach inside of gel:email with html tags works fine, but it implies that the arrayList has to be created in the same action script because global variables only store strings.

    And my target is to launch the query and the notification email in different steps.

    Also a global variable containing  html would enable to define the presentation format in a previous step



  • 7.  Re: gel: dynamic variables containing html

    Posted Jun 21, 2017 08:49 PM

    So I have play  around with saving json string (I saw gson.jar in the lib directory) in global variables which works.  The issue is that the global variables are limited to 4000 characters which doesn't allow for a very complex object.

     

    To get around the character limit,  I thought about writing the json string into a file (using the gel_objectInstanceId and gel_processInstanceId variable to provide a unique filename).  A downstream step would just read the file into a string and pass it back to gson to get an object.

     

    V/r,

    Gene