1016
Points
Questions
0
Answers
3
-
- 1341 views
- 4 answers
- 0 votes
-
You asked a simple question that requires a fairly complex answer, because one must account for static and dynamic lists, as well as flat and cascading lists.
The code below is a functioning groovy example of collecting list values for a given subclass and cell.
It works. i’m sure it can be improved, (i’m interested in any improvements to it). it runs on Agile 9.3.6// given:
// sdk – the agile session
// subclassName – the agile subclass name
// apiName – a given cell apiname
// return:
// the list of values, if any.subclass = sdk.getAgileClass(subclassName)
attribute = subclass.getAttribute(apiName)
listName = attribute?.getProperty(‘List’)?.getValue()
list = sdk.getAdmin().getListLibrary().getAdminList(listName as String)println “subclass|$subclass|attribute|$attribute|list|$list”
items = []
// STATIC LISTS
if( list.isEnumeratable() ) {// STATIC NON-CASCADED LISTS
if( !list.isCascaded()) {
items = list.getAdminList()?.getItems().findAll{it.isObsolete() == false} as String[]
}
// STATIC CASCADED LISTS
else {
items = []
adminList = list.getAdminList()
adminList.getItems().findAll{ it.isObsolete() == false}.each {
if (it.parentItemID == 0) {
it.children.each { items.add( “${it.name}|$it” )}
}
}
}} else { // DYNAMIC LISTS — Use the list’s query to get its items.
adminList = list.getAdminList()
criteria = sdk.getAdmin().getNode( adminList.getCriteria().getProperties()[‘ID’] )
QCLASS = (criteria) ? criteria.getCriteriaClass() : list.getListAgileClass()
QQUERY = (criteria) ? criteria.getCriteria() : “”items = sdk.query( QCLASS, QQUERY ).collect { row ->
value = row.getCells()[0]
// you could handle special cases here, for example:
if( QCLASS.toString() == ‘Users’) {
fname = row.getValue(‘firstName’)
lname = row.getValue(‘lastName’)
uid = row.getValue(‘userID’)
value = “$fname $lname ($uid)”
}
return value
}
// done.
}
println “items:(if any)”
items.each {println it}- 2124 views
- 3 answers
- 0 votes
-
- 2752 views
- 4 answers
- 0 votes