Search code examples
htmlxmlalfrescoactivitibusiness-process-management

How import a HTML file Template Email into an Activiti Task Email?


I've got this task in a BPMN Actitivi. I would like to put a template.html file into tag.

Is there any way?

Thanks

<serviceTask id="P3_EnviarEmail" name="Enviar Email Inicial" activiti:type="mail">
      <extensionElements>
        <activiti:field name="from">
          <activiti:string><![CDATA[info@xxx.om]]></activiti:string>
        </activiti:field>
        <activiti:field name="to">
          <activiti:string><![CDATA[xxxxx@gmail.com]]></activiti:string>
        </activiti:field>
        <activiti:field name="subject">
          <activiti:string><![CDATA[Comienzo del Evolutivo]]></activiti:string>
        </activiti:field>
        <activiti:field name="html">
          <activiti:string><![CDATA[ HERE HTML CODE ]


Solution

  • Finally, I found the solution using Java.

    I load files templates in Java, then I pass these to BPM like variables.

    This is the code

    JAVA

    @Autowired
    private ResourceLoader resourceLoader;
    
    public String getResources(String nombreFichero) throws IOException {
       String content = IOUtils.toString(resourceLoader.getResource("classpath:" + nombreFichero + ".html").getInputStream(),"UTF-8");
        return content;
    }
    
    String templateHeader = "";
        String templateFooter = "";
    
        try {
            templateHeader = getResources("templateHeader");        
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        try {
            templateFooter = getResources("templateFooter");            
        } catch (IOException e) {
            e.printStackTrace();
        }
    

    CALL TASK IN JAVA

        Map<String, Object> taskVariables = new HashMap<String, Object>();
        taskVariables.put("templateHeader", templateHeader);
        taskVariables.put("templateFooter", templateFooter);
    

    BPM

            <serviceTask id="P3_EnviarEmail" name="Enviar Email Inicial"
            activiti:type="mail">
            <extensionElements>
                <activiti:field name="from">
                    <activiti:string><![CDATA[xxxxxxx@xxx.com]]></activiti:string>
                </activiti:field>
                <activiti:field name="to">
                    <activiti:string><![CDATA[xxxxxxx@xxx.com]]></activiti:string>
                </activiti:field>
                <activiti:field name="subject" expression="Comienzo del Evolutivo ${evolutivo.nombre}" />
                <activiti:field name="html">
                    <activiti:expression>
                                <![CDATA[
                                    ${templateHeader}       
                                    ${templateFooter}
                                 ]]>            
                    </activiti:expression>
                </activiti:field>
            </extensionElements>
        </serviceTask>