Solution ID: prim80805
API Sample Code to list all Activity Codes that are assigned to a Project.
Status: Reviewed
Version(s): 6.0, 6.1, 6.2, 6.2.1

Problem: API Sample Code to list all Activity Codes that are assigned to a Project.
Fix:

 The following sample code will list all Activity Codes that are assigned in a specific project.  In this example, it will list all Activity Codes assigned in project ‘APEX’:


                  HashSet set = new HashSet();
                  BOIterator boiCodeAssignments = elm.loadActivityCodeAssignments(new String[]{“ProjectId”,”ActivityCodeTypeName”}, “ProjectId = ‘APEX’”,null);
                  while (boiCodeAssignments.hasNext()){
                        ActivityCodeAssignment codeAssignment = (ActivityCodeAssignment)boiCodeAssignments.next();
                        set.add(codeAssignment.getActivityCodeTypeName());                
                  }
                
                  Iterator iter = set.iterator();
         
                  // Loop through the list of Unique Codes
                  while(iter.hasNext()){
                      System.out.println(“\t”+ iter.next());
                  }
Fix: The following sample code will list all projects that contain Activity Code Assignments along with a list of the Activity Codes that are assigned in each project:

 
            EnterpriseLoadManager elm = mySession.getEnterpriseLoadManager();


            HashSet hashset = new HashSet();
            String currentProj = null;           


            BOIterator boiActCodeAssignments = elm.loadActivityCodeAssignments(new String[]{“ActivityCodeTypeName”,”ProjectId”}, null, “ProjectId”);
 
            while( boiActCodeAssignments.hasNext()){


                  ActivityCodeAssignment codeAssignment = (ActivityCodeAssignment)boiActCodeAssignments.next();                        


                  if(currentProj == null){
                      currentProj = codeAssignment.getProjectId();  
                      System.out.println(currentProj);
                  }


                  if (currentProj.equals(codeAssignment.getProjectId())==false){


                      Iterator iter = hashset.iterator();
                             
                      // Loop through the list of Unique Codes
                      while(iter.hasNext()){
                            System.out.println(“\t” + iter.next());
                      }
                      hashset.clear();
                      currentProj = codeAssignment.getProjectId();
                      System.out.println(currentProj);
                              
                  }


                  hashset.add(codeAssignment.getActivityCodeTypeName());
            }