Trying to get all the P3 list names and list values of all subclasses through SDK

Hello,

I am trying to retrieve all the list names of the P3 fields of the subclasses and their available values. However, I am not able to retrieve the available values of the lists. 

Here is the code: 
IAdmin admin = session.getAdminInstance();
IListLibrary list = admin.getListLibrary();
String propList = attr.getValue(PropertyConstants.PROP_LIST).toString();
IAdminList listt = list.getAdminList(propList);
System.out.println(“Listt: “+ listt);
IAgileList listvalue = listt.getValues(); // this gives null

Any input would be appreciated, thank you in advance!

Add Comment
3 Answer(s)

Hi Nagma,

What does this line of your code signify? String propList = attr.getValue(PropertyConstants.PROP_LIST).toString(); What is the attr object? From where are you retrieving it?

If am not wrong, you want to get all lists and their values which are used in any P3 attribute of all available subclasses in your system, right?

Agile Expert Answered on November 2, 2018.
Add Comment

Based on my understanding of your requirement, here is a small code snippet which you may like to leverage to build up your program:

IAdmin admin = session.getAdminInstance();
IAgileList list;
for(IAgileClass ac : admin.getAgileClasses(IAdmin.CONCRETE)){
      System.out.println(ac.getName());
      for(IAttribute at : ac.getAttributes()){
           if(at.getFullName().startsWith(“Page Three”)){
                 list = at.getAvailableValues();
                 if(list!=null && list.getAdminList() != null){
                     System.out.println(at.getFullName()+” –> “);
                     if(list.getAdminList().getValues().getChildNodes() !=null){
                         for(Object tn : list.getAdminList().getValues().getChildNodes()){
                              System.out.println(((IAgileList)tn).getValue());
                         }
                     }
                 }
            }
      }
}
session.close();
Runtime.getRuntime().exit(0);

Agile Expert Answered on November 2, 2018.

i don’t think this handles dynamic lists.

on December 2, 2018.

Hi Swagto,
I have similar requirement. But by using your method still I can not see value for Title Block.Lifecycle Phase. I can see values from list for other fields but not for LCP.
If you can help please refer below link for more details.

https://myagileplm.com/questions/how-to-get-lifecycle-associated-with-part-type/

Thanks,
Vaibhav

on May 8, 2019.
Add Comment

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}

Agile Angel Answered on December 2, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.