cancel
Showing results for 
Search instead for 
Did you mean: 

workflow advances variables always undefined

haroldvera
Champ in-the-making
Champ in-the-making
i have this decision in my workflow,

<decision name="tiene email">
        <event type="node-enter">
          <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>
           <variable name="bpm_package" access="read" />   
           <expression>
              &lt;import resource="/Company Home/Data Dictionary/Scripts/my_wf_logic.js"&gt;
              dnswf_tieneMail="no";
              tieneEmail(bpm_package);
              executionContext.setVariable("dnswf_tieneMail",dnswf_tieneMail);
           </expression>
           <variable name="dnswf_tieneMail" access="write"/>
          </script>
         </action>
        </event>

      <transition to="espera notificacion" name="si">
          <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
               <script>
                 <variable name="timeRepresentante" access="write"/>
                 <expression>
                     timeRepresentante='2 business days';
                 </expression>
            </script>
          </action>
          <condition>#{dnswf_tieneMail=="si"}</condition>
      </transition>
      <transition to="imprime y envia carta" name="no">
         <condition>#{dnswf_tieneMail=="no"}</condition>
      </transition>
      
   </decision>

my_wf_logic.js
————————————
var tieneEmail = function(bpm_package){
   for (var a = 0; a < bpm_package.children.length; a++)
      {
        if(bpm_package.children[a].properties["cm:categories"]!=undefined && bpm_package.children[a].properties["cm:categories"]!=null){
           for (var b = 0; b < bpm_package.children[a].properties["cm:categories"].length; b++){
              if (bpm_package.children[a].properties["cm:categories"].properties["cm:name"]=="cartas representante"){
              if((bpm_package.children[a].properties["mtt:emailCiudadano"]!=undefined && bpm_package.children[a].properties["mtt:emailCiudadano"]!=null)){
                                       dnswf_tieneMail="si";
                                  }
              }
           }
                  }
           }
}


if I debug the javascript code, the variable takes the value dnsw_tieneEmail "yes" but the value is undefined in the decision. I appreciate any assistance.
1 REPLY 1

hyperation
Champ on-the-rise
Champ on-the-rise
Hi,

Your workflow transition is probably just defaulting to the first decision, which is the "Yes" one.

You can try setting the variable again in an "task-end" event before doing the transition and see if the variable persists.

Thanks
Smiley Happy