This the relevant snippet that I ended up with, thanks to help from Jama Software:
#set($docDao = $applicationContext.getBean("documentDao"))
#set($contourItemDao = $applicationContext.getBean("contourItemDao"))
#set($documentTypeFieldDao = $applicationContext.getBean("documentTypeFieldDao"))
<table>
#####Get the docs in the project #########
#set($projectDocIds = $contourItemDao.getContourItemIdsForProject($mathTool.toInteger($project.id)))
#set($found = 'no')
#set($docList = []) ##$docList will be an array of arrays
## cycle through all of the items in the project
#foreach ($projectDocId in $projectDocIds)
#set($baseDoc = $docDao.getDocument($mathTool.toInteger($projectDocId)))
#foreach ($myDoc in $docList)
## Have the fields for this item type already been added to the $docList array?
#if ($myDoc.get(0) == $baseDoc.documentType.id)
## This Item Type has already been seen so move onto the next item
#set($found = 'yes')
#break
#end
#end ##end of foreach
#if($found == 'no')
## if the item type hasn't already been seen, add the field names to the $docFields array
#set($docFields = [])
#foreach ($d in $documentTypeFieldDao.getDocumentTypeFieldListByType($baseDoc.documentType.id))
#if($docFields.add($d.documentField.name)) #end
#end
#if($docList.add($docFields)) #end ##Add the $docFields array as an entry in the $docList array
#end
#set($found = 'no')
#end
## For each item type included in $docList...
#foreach($item in $docList)
<tr>
## For each field defined for that item type....
#foreach($fieldName in $item)
<td>$fieldName</td> ## print the name of that field
#end
</tr>
#end
</table>
------------------------------
Debra Shannon
Sentek Global
San Diego CA
------------------------------
Original Message:
Sent: 05-03-2018 20:29
From: Debra Shannon
Subject: Velocity - loop through item types
I've been trying to figure out how to loop through item types of the current project. My goal is to list the field names defined for each item type.
But I can't even get to first base (declaring the class). I've tried the following but all of these cause the script to fail.
#set($projectTypes = $applicationContext.getBean("ProjectType"))
#set($projectTypeFields = $applicationContext.getBean("ProjectTypeField"))
#set($projectTypes = $applicationContext.getBean("ProjectTypeDao"))
#set($projectTypeFields = $applicationContext.getBean("ProjectTypeFieldDao"))
#set($documentTypes = $applicationContext.getBean("DocumentTypeDao"))
#set($documentNodeManager = $applicationContext.getBean("documentNodeManager"))
I have 3 questions:
1. Which class can I use to loop through the item types?
2. Are all 6 of these non-operational or am I doing something wrong?
3. If all 6 of these are non-operational then is there a master list of classes that do work?
Thanks.
Debbie
------------------------------
Debra Shannon
Sentek Global
San Diego CA
------------------------------