Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Dear,
I'm trying to save the username of the user Entered in the "setup participants" as String attribute in the document.
Using the code below, it returns me the id of the user, for example wt.org.WTUser:58330. The document attribute i want to save is the "elab".
Can we help me find a way to turn this username in the User ID? The code below is embedded in the task transitions> complete.
wt.org.WTPrincipal wtprincipalelab=null;
wt.org.WTPrincipal wtprincipalverif=null;
final String roleElaborador= "ELABORADOR";
wt.workflow.engine.WfProcess wfprocess = ((wt.workflow.work.WfAssignedActivity)self.getObject()).getParentProcess();
java.util.Enumeration pinwf = wfprocess.getPrincipals(wt.project.Role.toRole(roleElaborador));
int count = 0;
while (pinwf.hasMoreElements()){
wtprincipalelab = ((wt.org.WTPrincipalReference)pinwf.nextElement()).getPrincipal();
elab=wt.fc.PersistenceHelper.getObjectIdentifier((wt.org.WTUser)wtprincipalelab).toString();
System.out.println("ELAB**************:"+ elab);
count = count+1;
}
//System.out.println("VALOR DO COUNT (ELABORADOR) ******************"+ count);
if(count==0){
throw new wt.util.WTException(new Throwable(new String("Informe o Elaborador!")));
}
Thanks,
Felipe Oliveira
Solved! Go to Solution.
try following and see if anyone works for you.
Replace
System.out.println("ELAB**************:"+ elab);
with (any one)
System.out.println("ELAB**************:"+ wtprincipalelab.getName());
System.out.println("ELAB**************:"+ wtprincipalelab.getDisplayIdentity());
System.out.println("ELAB**************:"+ wtprincipalelab.getPrincipalDisplayIdentifier());
try following and see if anyone works for you.
Replace
System.out.println("ELAB**************:"+ elab);
with (any one)
System.out.println("ELAB**************:"+ wtprincipalelab.getName());
System.out.println("ELAB**************:"+ wtprincipalelab.getDisplayIdentity());
System.out.println("ELAB**************:"+ wtprincipalelab.getPrincipalDisplayIdentifier());
Thank you,
Worked with the following code:
wt.org.WTPrincipal wtprincipalelab=null;
wt.org.WTPrincipal wtprincipalverif=null;
String elab2=null;
final String roleElaborador= "ELABORADOR";
wt.workflow.engine.WfProcess wfprocess = ((wt.workflow.work.WfAssignedActivity)self.getObject()).getParentProcess();
java.util.Enumeration pinwf = wfprocess.getPrincipals(wt.project.Role.toRole(roleElaborador));
int count = 0;
System.out.println("ANTES DO WHILE");
while (pinwf.hasMoreElements()){
wtprincipalelab = ((wt.org.WTPrincipalReference)pinwf.nextElement()).getPrincipal();
elab2=(wtprincipalelab).getName();
System.out.println("ELAB2**************:"+ elab2);
elab=(elab2).toString();
System.out.println("ELAB**************:"+ elab);
count = count+1;
I know this post is a year old, but I just wanted to circle back and mention that I appreciate you sharing this code. I've wanted to implement this for quite a long time. I just never got around to it.
In my case, I wanted to save the list of users in a certain role to a workflow variable called tester. Later, an email notification is sent that calls out the tester variable in the email message. Here is my implementation (workflow expression robot after the setup participants task is completed). It might not be the most efficient way, but it works. I also haven't taken the time to move this into a custom class yet. So still calling it out from a workflow expression robot for now.
Thanks to Yogesh Bagul also, for the mention of getPrincipalDisplayIdentifier().
java.util.Enumeration list = null;
wt.org.WTPrincipal principal = null;
wt.workflow.engine.WfProcess wfprocess = null;
tester = ""; // this is a workflow variable, so doesn't need to get instantiated
try {
// Try to get the workflow process from "self"
if(self.getObject().getClass().isAssignableFrom(wt.workflow.engine.WfProcess.class)){
wfprocess = (wt.workflow.engine.WfProcess)self.getObject();
}
// Create a list of the users in the TESTER role
list = wfprocess.getPrincipals(wt.project.Role.toRole("TESTER"));
// Go through the list and add the user's full name to the variable "tester"
while (list.hasMoreElements()){
principal = ((wt.org.WTPrincipalReference)list.nextElement()).getPrincipal();
tester += principal.getPrincipalDisplayIdentifier() + " & ";
}
// Trim the last 3 characters which are: " & "
if (tester.length() > 3) {
tester = tester.substring(0, tester.length()-3);
}
} catch (wt.util.WTException wex) {
System.out.println(wex.getLocalizedMessage());
}
Good to know that even after a year, sent content continues to help people.
This is how a community works!
Thanks for the feedback and good luck.
Felipe.