AnsweredAssumed Answered

Creating an array of users from associations

Question asked by srowsell on Jan 17, 2014
Latest reply on Jan 17, 2014 by srowsell
I have created a datalist (whose model is shown below, along with everything else) with two properties I need to turn into an array in a web script:  recipientGroup and recipientUser.  These are both multi-valued fields which are associations to groups and users, respectively.

What I need to do with this list is go through it and create an array for each of these associations:  groupArray and userArray.  I will then use these to start workflows.  My problem is that I just can't seem to get my head around how these work as objects.  The snippet I'm posting shows that I'm trying to include a list of unique groups and users, but since the comparison (as shown in a comment) always fails, the arrays are full of non-unique entries.

Any thoughts?

The datalist model:

<?xml version="1.0" encoding="UTF-8"?>
<!– Definition of new Model –>
<model xmlns="http://www.alfresco.org/model/dictionary/1.0" name="reportdl:reportRecipientsDatalist">
   <!– Optional meta-data about the model –>
   <description>Reports Data List</description>
   <author>Steve Rowsell</author>
   <version>1.0</version>
   <!– Imports are required to allow references to definitions in other models –>
   <imports>
      <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
      <!– Import Alfresco Data List Model Definitions –>
      <import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl" />
   </imports>
   <!– Introduction of new namespaces defined by this model –>
   <namespaces>
      <namespace uri="com.duca.reports.datalist" prefix="reportdl" />
   </namespaces>
   <constraints>
      <constraint name="reportdl:departments" type="LIST">
         <parameter name="allowedValues">
            <list>
               <value>Accounting</value>
               <value>Audit</value>
               <value>Credit</value>
               <value>Deposits</value>
               <value>Facilities</value>
               <value>Human Resources</value>
               <value>Investment Solutions</value>
               <value>IT</value>
            <value>Loans</value>
               <value>Marketing</value>
               <value>Operations</value>
               <value>Property Leases</value>
               <value>Sales &amp; Service</value>
            <value>Bowmanville</value>
               <value>Brampton - HCH</value>
               <value>Brampton - Main</value>
               <value>Burlington</value>
               <value>Call Centre</value>
               <value>CBC</value>
               <value>Erin Mills</value>
               <value>Etobicoke</value>
               <value>Guelph</value>
               <value>Mississauga</value>
               <value>Molson</value>
               <value>Mount Pleasant</value>
               <value>Newmarket</value>
            <value>Orangeville</value>
            <value>Pickering</value>
            <value>Rexdale</value>
            <value>Richmond Hill</value>
            <value>Whitby</value>
            <value>Willowdale</value>
<value>Unknown</value>
         </list>
         </parameter>
      </constraint>
      <constraint name="reportdl:frequencies" type="LIST">
         <parameter name="allowedValues">
            <list>
               <value>Daily</value>
               <value>Weekly</value>
               <value>Bi-Weekly</value>
               <value>Monthly</value>
               <value>Bi-Monthly</value>
               <value>Semi-Annually</value>
               <value>Annually</value>
               <value>On Demand</value>
<value>Unknown</value>
            </list>
         </parameter>
      </constraint>
   </constraints>
   <!–      T Y P E   D E F I N I T I O N S      –>
   <types>
      <!–   Data list defintions For this model go here –>
      <type name="reportdl:reportRecipientsDatalist">
         <title>Reports Data List</title>
         <description>Report Recipients Data List</description>
         <parent>dl:dataListItem</parent>
         <properties>
            <property name="reportdl:department">
               <title>Department</title>
               <type>d:text</type>
               <mandatory>true</mandatory>
               <constraints>
                  <constraint ref="reportdl:departments" />
               </constraints>
            </property>
            <property name="reportdl:reportName">
               <title>Report Name</title>
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
<property name="reportdl:uniqueIdentifier">
               <title>Report Unique Identifier</title>
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
            <property name="reportdl:frequency">
               <title>Report Frequency</title>
               <type>d:text</type>
               <mandatory>true</mandatory>
               <constraints>
                  <constraint ref="reportdl:frequencies" />
               </constraints>
            </property>
            <property name="reportdl:suffix">
               <title>Suffix</title>
               <type>d:text</type>
               <mandatory>false</mandatory>
            </property>
         </properties>
         <associations>
            <association name="reportdl:recipientGroup">
               <title>Recipient Group</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:authorityContainer</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
            <association name="reportdl:recipientUser">
               <title>Recipient User</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:person</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>
   </types>
</model>


The javascript snippet from the web script:

if ((child.assocs["reportdl:recipientGroup"])!=null)
{
   for (var i=0;i<(child.assocs["reportdl:recipientGroup"]).length;i++)
   {
      var inTheList=false;
      for (var j=0;j<groupArray.length;j++)
      {
         if (groupArray[j]==(child.assocs["reportdl:recipientGroup"])) //this is always false
         {
            inTheList=true;
         }
      }
      if (!inTheList)
      {
         groupArray.push(child.assocs["reportdl:recipientGroup"]);
      }
   }
}

Outcomes