Add User to Multiple Projects By Script

From C3 Wiki

Jump to: navigation, search

[edit] Summary

At times it may be necessary to add a user to a set of person on multiple projects. In these cases, a command console script is a quick way to build a query of the relevant studies and then loop through and add the person in the appropriate spot. The code below refers to custom attributes and should be edited to match the query you want to run, the OID of the person you want to add, and the attribute of the set you wish to populate. Just as a tip, console scripts usually run slowest on the first run and can timeout. It's often helpful to run the script the first time with the actual work of adding to sets commented out. This allows the script to run through gathering the projects and iterating through them. The next run will generally be faster and more efficient at doing the actual work.

As with any console script, do not run in production until you have thoroughly tested it in a duplicate, nonproduction environment.

[edit] Code Sample


//SEM 4-9-08 Command Console Script
//Script searches for studies by criteria and adds a new person to the Study team members set
results=ApplicationEntity.getResultSet("_Protocol").query("status.ID = 'Active'").elements;
var newPerson = wom.getEntityFromString("com.webridge.account.Person[OID[92AC41F9F7FD8840950097723D9BAAC2]]"); //OID of Person's account
var count = 0 //set a variable to increment as studies are processed

for( var i=1;i<=results.count();i++){
  //For each returned study,see if it meets certain criteria and do the work
   var CancerStudy = results.item(i).getQualifiedAttribute("customAttributes._attribute210.customAttributes._attribute6");
   var SetStudyTeam = results.item(i).getQualifiedAttribute("customAttributes._attribute268"); //Application.Study Team Members
      if(CancerStudy==true && !SetStudyTeam.contains(newPerson)){
      //SetStudyTeam.addElement(newPerson); //Uncomment this line to Add new person to Study Team set
      ?"name of study==  "+results.item(i).ID+"\n"; //print out study title for each returned
      count+=1; //increment count
  }
}
?"Count: " +count;
?"Done \n";