cancel
Showing results for 
Search instead for 
Did you mean: 

processTemplate in a workflow

c_durmont
Champ in-the-making
Champ in-the-making
Hello there,

I'm trying to build a somewhat complex workflow using alfresco 1.4 Community and jBPM.
I'd like to do the following during a transition:
- copy some task variables to a document's properties
- apply a template to that document and have the result set as the content of the document.

Hence the javascript code:

var myRoot=bpm_context.parent; // a workaround for the missing company_home root object
var model=myRoot.childByNamePath('Dictionnaire des Données/Modèles de Présentation/doc_info.ftl');
var generatedDoc=bpm_package.children[0];
// set some properties
generatedDoc.properties['xxx']=yyy;

var result=generatedDoc.processTemplate(model);
generatedDoc.content=result;

That would be on a perfect world, BUT:
- line 2 : the  childByNamePath gives me a strange error on the log : it says "wrapped java.lang.classCastException: org.mozilla.javascript.uniqueTag (AlfrescoScript#1)" (no more details). I can work around this by selecting the model with myRoot.children[x].children[y]…
- the processTemplate command also generates a "uniqueTag" error.

What's going on ? Where do that "uniqueTag" error come from ?
For information, I have tested the following:
- myRoot variable really contains the root node
- model variable really contains the model node (with the workaround explained above)
- generatedDoc is my package document, and properties setting work as expected
- I have the same result if I call processTemplate(model.content) (passing the template string instead of the template node)
- I have the same result if I call bpm_package.processTemplate() any_node_i_know.processTemplate()
6 REPLIES 6

davidc
Star Contributor
Star Contributor
I don't believe we've seen that exception before.

No obvious solutions spring to mind.

Would you mind posting your full workflow definition & template (in case you've modified it)?

With those, we can reproduce and get to root of the problem.

c_durmont
Champ in-the-making
Champ in-the-making
ok, let's go for the huge post:
the process definition:

<?xml version="1.0" encoding="UTF-8"?>

<process-definition
  xmlns="urn:jbpm.org:jpdl-3.1"  name="wf:arbitrag">
   <swimlane name="initiator" />
   <swimlane name="chef">
      <assignment actor-id="#{wf_chef.properties['cm:userName']}" />
   </swimlane>
   <swimlane name="csag">
      <assignment actor-id="#{wf_csag.properties['cm:userName']}" />
   </swimlane>
   <swimlane name="directeur">
      <assignment actor-id="#{wf_dir.properties['cm:userName']}" />
   </swimlane>
   <swimlane name="dga">
      <assignment actor-id="#{wf_dga.properties['cm:userName']}" />
   </swimlane>
  
   <start-state name="debut">
      <task name="wf:arbiDebut" swimlane="initiator"></task>
      <transition name="trCree" to="redaction">
      </transition>
   </start-state>
   <task-node name="validation chef">
      <task name="wf:arbiValidChef" swimlane="chef"></task>
      <transition name="trValidCsag" to="validation CSAG"></transition>
      <transition name="trAjourne" to="redaction"></transition>
   </task-node>
   <task-node name="validation CSAG">
      <task name="wf:arbiValidCsag" swimlane="csag"></task>
      <transition name="trValidDir" to="validation directeur"></transition>
      <transition name="trRefuseCsag" to="validation chef"></transition>
   </task-node>
   <task-node name="validation directeur">
      <task name="wf:arbiValidDir" swimlane="directeur"></task>
      <transition name="trValidDga" to="validation DGA"></transition>
      <transition name="trRefuseDir" to="validation CSAG"></transition>
   </task-node>
   <task-node name="validation DGA">
      <task name="wf:arbiValidDga" swimlane="dga"></task>
      <transition name="trValide" to="Accepte"></transition>
      <transition name="trRefuseDga" to="validation directeur"></transition>
   </task-node>
   <task-node name="Accepte">
      <task name="wf:arbiValid" swimlane="initiator"></task>
      <transition name="trFicheValidee" to="fin"></transition>
   </task-node>
   <end-state name="fin"></end-state>
   <task-node name="redaction">
      <task name="wf:arbiRedac" swimlane="initiator"></task>
      <transition name="trValidChef"  to="validation chef" >
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
            var racine=bpm_context.parent;
            var docGenere=bpm_package.children[0];
            docGenere.addAspect("wf:arbiAspect");
            docGenere.properties['wf:montant']= wf_montant;
            docGenere.properties['wf:commission']= wf_commission;
            docGenere.properties['wf:objet']= bpm_workflowDescription;
            docGenere.properties['wf:beneficiaire']= wf_beneficiaire;
            var result=docGenere.processTemplate(racine.children[5]);
            docGenere.content=result;
            </script>
         </action>     
      </transition>
      <transition name="trValidDirectCsag" to="validation CSAG"></transition>
      <transition name="trAbandon" to="fin"></transition>
   </task-node>
</process-definition>

'Not sure of what's a "workflow template", but here is the workflow content model :

<?xml version="1.0" encoding="UTF-8"?>

<model name="wf:workflowmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <imports>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm"/>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
   </imports>

   <namespaces>
    <namespace uri="http://www.alfresco.org/model/workflow/1.0" prefix="wf"/>
   </namespaces>

    <constraints>
        <constraint name="wf:listeCommissions" type="LIST">
            <parameter name="allowedValues">
                <list>
                    <value>Commission 1</value>
                    <value>Commission 2</value>
                    <value>Commission 3</value>
                    <value>Commission 4</value>
                    <value>Commission 5</value>
                    <value>Commission 6</value>
                    <value>Commission 7</value>
                    <value>Commission S</value>
                </list>
            </parameter>
        </constraint>
   </constraints>

   <types>
   
    <type name="wf:arbiDebut">
      <parent>bpm:startTask</parent>
      <mandatory-aspects>
         <aspect>wf:arbiAspect</aspect>
      </mandatory-aspects>
    </type>
    <type name="wf:arbiRedac">
      <parent>bpm:startTask</parent>
      <mandatory-aspects>
         <aspect>wf:arbiAspect</aspect>
      </mandatory-aspects>
    </type>

    <type name="wf:arbiValidChef">
      <parent>bpm:workflowTask</parent>
      <mandatory-aspects>
         <aspect>wf:arbiAspect</aspect>
      </mandatory-aspects>
    </type>
    <type name="wf:arbiValidCsag">
      <parent>bpm:workflowTask</parent>
      <mandatory-aspects>
         <aspect>wf:arbiAspect</aspect>
      </mandatory-aspects>
    </type>
    <type name="wf:arbiValidDir">
      <parent>bpm:workflowTask</parent>
      <mandatory-aspects>
         <aspect>wf:arbiAspect</aspect>
      </mandatory-aspects>
    </type>
    <type name="wf:arbiValidDga">
      <parent>bpm:workflowTask</parent>
      <mandatory-aspects>
         <aspect>wf:arbiAspect</aspect>
      </mandatory-aspects>
    </type>
    <type name="wf:arbiValid">
      <parent>bpm:workflowTask</parent>
      <mandatory-aspects>
         <aspect>wf:arbiAspect</aspect>
      </mandatory-aspects>
    </type>


      
   </types>
   
   
   <aspects>
      <aspect name="wf:arbiAspect">
         <properties>
            <property name="wf:objet">
               <type>d:text</type>
            </property>
            <property name="wf:montant">
               <type>d:float</type>
               <default>0</default>
            </property>
            <!– normalement déterminé par le workflow
            <property name="wf:nomCsag">
               <type>d:text</type>
            </property>
            <property name="wf:nomDir">
               <type>d:text</type>
            </property>
            <property name="wf:nomDga">
               <type>d:text</type>
            </property>
            <property name="wf:nomElu">
               <type>d:text</type>
            </property>
            –>
            <property name="wf:commission">
               <type>d:text</type>
               <constraints>
                  <constraint ref="wf:listeCommissions" />
               </constraints>         
            </property>
            <property name="wf:axe">
               <type>d:text</type>
            </property>
            <property name="wf:beneficiaire">
               <type>d:text</type>
            </property>
            <property name="wf:investissement">
               <type>d:boolean</type>
               <default>false</default>
            </property>
            <property name="wf:fonctionnement">
               <type>d:boolean</type>
               <default>false</default>
            </property>
            <property name="wf:renouvellement">
               <type>d:boolean</type>
               <default>false</default>
            </property>
            <property name="wf:dateInitiale">
               <type>d:date</type>
            </property>
            <!– AP/AE –>
            <property name="wf:apaeInscrites">
               <type>d:float</type>
               <default>0</default>
            </property>
            <property name="wf:apaeDispo">
               <type>d:float</type>
               <default>0</default>
            </property>
            <property name="wf:apaeDateDispo">
               <type>d:date</type>
            </property>
            <property name="wf:apaeAnterieur">
               <type>d:text</type>
            </property>
            <!– PRECISIONS –>
            <property name="wf:preciseContexte">
               <type>d:text</type>
            </property>
            <property name="wf:preciseAutresRegions">
               <type>d:text</type>
            </property>
            <property name="wf:precisePartenariats">
               <type>d:text</type>
            </property>
            <property name="wf:preciseValAjout">
               <type>d:text</type>
            </property>
            <!– COMMENTAIRES –>
            <property name="wf:commentService">
               <type>d:text</type>
            </property>
            <property name="wf:commentChef">
               <type>d:text</type>
            </property>
            <property name="wf:commentCsag">
               <type>d:text</type>
            </property>
            <property name="wf:commentDir">
               <type>d:text</type>
            </property>
            <property name="wf:commentDga">
               <type>d:text</type>
            </property>
            
         </properties>
         
            <associations>

                <association name="wf:chef">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>cm:person</class>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </target>
                </association>
                <association name="wf:csag">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>cm:person</class>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </target>
                </association>
                <association name="wf:dir">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>cm:person</class>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </target>
                </association>
                <association name="wf:dga">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>cm:person</class>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </target>
                </association>

            </associations>
      </aspect>
   </aspects>
   

   
</model>

Do you need anything else ?

davidc
Star Contributor
Star Contributor
Thanks, I'll take a look.

Re: the template.  I meant could you post the freemarker template you're using - the one referenced at:

 var result=docGenere.processTemplate(racine.children[5]); 

That should be all we need.

c_durmont
Champ in-the-making
Champ in-the-making
it's just a verbatim copy of doc_info.ftl
I put it on the root space because I was investigating whether the characters with accents ( é, è etc.) are the source of the first error (childByNamePath). And it wasn't.

davidc
Star Contributor
Star Contributor
Ok, I've managed to reproduce.

It's a bug in the workflow/javascript/freemarker integration due to missing javascript root objects 'person', 'userhome' and, in your case, 'companyhome'.

There's a workaround.

You can set these root objects in your workflow definition.  Add the following script to the exit point of the start state.


   <start-state name="debut">
      …
      <event type="node-leave">
         <script>
            <variable name="person" access="write" />
            <variable name="userhome" access="write" />
            <variable name="companyhome" access="write" />
            <expression>
               person = initiator;
               userhome = initiatorhome;
               companyhome = bpm_context.parent;
            </expression>
         </script>
      </event>
   </start-state>
Post 1.4 community final, a fix has already been made to provide companyhome.  I'll provide a further fix to add person and userhome.

davidc
Star Contributor
Star Contributor