How can I check if an association is empty?

cancel
Showing results for 
Search instead for 
Did you mean: 
mafaldap
Active Member II

How can I check if an association is empty?

I've three associations added to the workflow's form by an aspect:

<aspect name="psw:allegabile">
               <associations>
                    <association name="psw:docDRC">
                         <title>Domanda di Ricostruzione di Carriera</title>
                         <source>
                              <mandatory>true</mandatory>
                              <many>false</many>
                         </source>
                         <target>
                              <class>cm:content</class>
                              <mandatory>true</mandatory>
                              <many>false</many>
                         </target>
                    </association>
                    <association name="psw:docAS">
                         <title>Autocertificazione dei Servizi</title>
                         <source>
                              <mandatory>true</mandatory>
                              <many>false</many>
                         </source>
                         <target>
                              <class>cm:content</class>
                              <mandatory>true</mandatory>
                              <many>false</many>
                         </target>
                    </association>
                    <association name="psw:docAllegati">
                         <title>Documenti allegati</title>
                         <source>
                              <mandatory>false</mandatory>
                              <many>true</many>
                         </source>
                         <target>
                              <class>cm:content</class>
                              <mandatory>false</mandatory>
                              <many>true</many>
                         </target>
                    </association>
               </associations>
          </aspect>

I need to move the documents between folders during the workflow. The move function works for the mandatory associations but I can't find how to check if psw:docAllegati is empty. Any idea?

1 Reply
mafaldap
Active Member II

Re: How can I check if an association is empty?

Ok, maybe I found a solution, but it still gives me an error. This time says:

org.alfresco.scripts.ScriptException: 10200004 Failed to execute supplied script: missing ) after condition (AlfrescoJS#5)

I checked the code but I can't see any missing )

<userTask id="approvaDRC" name="Approva Domanda di Ricostruzione di Carriera" activiti:formKey="psw:activitiApprovaDRC">
         <extensionElements>
              <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"> 
                    <activiti:field name="script"> 
                         <activiti:string> 
                                <![CDATA[if(task.getVariableLocal('psw_esitoValutazioneDRC') == 'Approvata'){
                             execution.setVariable('psw_proseguiDRC', true);
                              var dest = companyhome.childByNamePath("/Ragionerie dello Stato");
                              psw_docDRC.move(dest);
                              psw_docAS.move(dest);
                              if(psw_docAllegati.children.length &gt; 0){
                                       for(var i = 0; i &lt; psw_docAllegati.children.length; i++ ){
                                       psw_docAllegati.children[i].move(dest);
                                       }
                                  }
                             }else{
                             execution.setVariable('psw_proseguiDRC', false);
                             }]]>

                         </activiti:string> 
                    </activiti:field>
                    <activiti:field name="runAs">
                         <activiti:string>admin</activiti:string>
                    </activiti:field> 
               </activiti:taskListener>
         </extensionElements>
         <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${bpm_assignee.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
        </humanPerformer>
    </userTask>

<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="protocollaDRC">
         <extensionElements>
              <activiti:executionListener event="take" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
                   <activiti:field name="script">
                        <activiti:string>
                             <![CDATA[
                                  var gruppo = bpm_groupAssignee.properties["cm:authorityName"];
                                  var dest = companyhome.childByNamePath("/"+gruppo);
                                   psw_docDRC.move(dest);
                                  psw_docAS.move(dest);
                                  if (psw_docAllegati.children.length &gt; 0){
                                       for (var i = 0; i &lt; psw_docAllegati.children.length; i++){
                                            psw_docAllegati.children[i].move(dest);
                                       }
                                  }]]>

                        </activiti:string>
                   </activiti:field>
              </activiti:executionListener>
         </extensionElements>
    </sequenceFlow>