cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Set Up Participants - Role Check

Cosmo
1-Newbie

Set Up Participants - Role Check


Hi All,
I have two problems I'm trying to solve:
1) How do I keep the workflow from hanging if the user completes a task without actually selecting a participant in the Set Up Participants section?
2) How do I get the value of the user assigned to the role in the Set Up Participants task? I want to use this in a workflow variable for something else.


I suspect that I need expression robots to do this but I'm not sure what the syntax should be. Does anyone have any sample syntax they'd be willing to share to get this accomplished?
For the second issue, I received the following from PTC Tech Support but it always returns the value of "null" for UserName even though the "Change Admin I" role always has someone in it.
wt.doc.WTDocument doc =
(wt.doc.WTDocument)primaryBusinessObject;

wt.team.Team pbOteam =
wt.team.TeamHelper.service.getTeam(doc);

wt.team.RoleHolder2 rh =
(wt.team.RoleHolder2)pbOteam;

java.util.Enumeration princ =
rh.getPrincipalTarget(wt.project.Role.toRole("Change Admin I"));

while (princ.hasMoreElements())
{


wt.org.WTPrincipalReference pRef =
(wt.org.WTPrincipalReference)princ.nextElement();

UserName = pRef.getFullName
( );

System.out.println
(" Name is " + UserName);

}

Unique_Comments_Out=Unique_Comments_Out+"
- "+UserName;
Mike -

6 REPLIES 6
RandyJones
19-Tanzanite
(To:Cosmo)

On 12/06/10 17:35, Michael Kramer wrote:
> Hi All,
>
> I have two problems I'm trying to solve:
>
> 1) How do I keep the workflow from hanging if the user completes a task without actually selecting a participant in the Set Up Participants section?
>
> 2) How do I get the value of the user assigned to the role in the Set Up Participants task?  I want to use this in a workflow variable for something else.
>
>
> I suspect that I need expression robots to do this but I'm not sure what the syntax should be.  Does anyone have any sample syntax they'd be willing to share to get this accomplished?
>
> For the second issue, I received the following from PTC Tech Support but it always returns the value of "null" for UserName even though the "Change Admin I" role always has someone in it.
>
> wt.doc.WTDocument doc = (wt.doc.WTDocument)primaryBusinessObject;
>
> wt.team.Team pbOteam = wt.team.TeamHelper.service.getTeam(doc);
>
> wt.team.RoleHolder2 rh = (wt.team.RoleHolder2)pbOteam;
>
> java.util.Enumeration princ = rh.getPrincipalTarget(wt.project.Role.toRole("Change Admin I"));
>
> while (princ.hasMoreElements()) {
>
>    wt.org.WTPrincipalReference pRef = (wt.org.WTPrincipalReference)princ.nextElement();
>
Try adding getPrincipal() like this:
wt.org.WTPrincipalReference pRef = ((wt.org.WTPrincipalReference)princ.nextElement()).getPrincipal();

>    UserName = pRef.getFullName ( );
>
>    System.out.println (" Name is " + UserName);
>
> }
>
> Unique_Comments_Out=Unique_Comments_Out+" - "+UserName;
> Mike Kramer
> -  <">mailto:->
>
>
>
> ----------


--
------------------------------------------------------------------------
Randy Jones
Systems Administrator
Great Plains Mfg., Inc.
1525 E North St
PO Box 5060
Salina, KS USA 67401
email: -
Phone: 785-823-3276
   Fax: 785-667-2695
------------------------------------------------------------------------

tbusch
1-Newbie
(To:Cosmo)

Mike, you could try this:

/**
* Determines if a given role is populated for this specific instance of a team.
*
* @param role - the name of the role to check against.
* @param teamOid - the obid of the team instance.
* @return true if the role has at least one WTPrincipal in it, false if not.
* @throws WTException
*/

public static boolean isRolePopulated(String role, String teamOid) {
String localTeamOid = GeneralUtility.getLocalOid(teamOid);
ReferenceFactory rf = new ReferenceFactory();
WTReference ref;
try {
ref = rf.getReference(localTeamOid);
} catch (WTException e) {
log.error("Could not get team from obid " + teamOid + "(local oid: " + localTeamOid + ")", e);
return false;
}

if (ref == null) {
return false;
}

Team team = (Team) ref.getObject();
if (team == null) {
return false;
}

Map rpMap;
try {
rpMap = team.getRolePrincipalMap();
} catch (WTException e) {
log.error("Could not get RolePrincipalMap from team", e);
return false;
}
String resultOid = null;

Iterator iter = rpMap.keySet().iterator();

while(iter.hasNext()) {
Role nextRole = (Role) iter.next();
String mapRole = nextRole.getStringValue();
int lastPeriodLoc = mapRole.lastIndexOf(".");
if (lastPeriodLoc > -1) {
mapRole = mapRole.substring(lastPeriodLoc + 1);
}

if (mapRole.equalsIgnoreCase(role)) {
List users = (ArrayList) rpMap.get(nextRole);
if (users.size() > 0){
// role found & populated with one or more users
return true;
}
}
}

// Role not found or no user in role
return false;
}

FYI, here's GeneralUtility.getLocalOid() (which is kind of sloppy... sorry...):

/**
* Windchill may return an oid which includes the server information. This
* information must not be present when looking up objects based on the oid.
* This method searches for any information after a second colon (the
* extraneous information) and removes it.
*
* @param oid the oid to get a local oid for.
* @return a local oid
*/
public static String getLocalOid(String oid) {
if (oid == null)
return null;

if(oid.indexOf("[") == 0 && oid.lastIndexOf("]") == oid.length()-1) oid = oid.substring(1, oid.length() - 1);

int firstColonLocation = oid.indexOf(':');
int lastColonLocation = oid.lastIndexOf(':');
if (lastColonLocation > 0 && lastColonLocation > firstColonLocation)
return oid.substring(0, lastColonLocation);
else
return oid;
}


-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<">mailto:tom.busch@stryker.com>
sp-2
1-Newbie
(To:Cosmo)

Is there any way to display the alert message on the screen and tell the user that they haave to mandatorily select the participant?

In Reply to Thomas Busch:


Mike, you could try this:

/**
* Determines if a given role is populated for this specific instance of a team.
*
* @param role - the name of the role to check against.
* @param teamOid - the obid of the team instance.
* @return true if the role has at least one WTPrincipal in it, false if not.
* @throws WTException
*/

public static boolean isRolePopulated(String role, String teamOid) {
String localTeamOid = GeneralUtility.getLocalOid(teamOid);
ReferenceFactory rf = new ReferenceFactory();
WTReference ref;
try {
ref = rf.getReference(localTeamOid);
} catch (WTException e) {
log.error("Could not get team from obid " + teamOid + "(local oid: " + localTeamOid + ")", e);
return false;
}

if (ref == null) {
return false;
}

Team team = (Team) ref.getObject();
if (team == null) {
return false;
}

Map rpMap;
try {
rpMap = team.getRolePrincipalMap();
} catch (WTException e) {
log.error("Could not get RolePrincipalMap from team", e);
return false;
}
String resultOid = null;

Iterator iter = rpMap.keySet().iterator();

while(iter.hasNext()) {
Role nextRole = (Role) iter.next();
String mapRole = nextRole.getStringValue();
int lastPeriodLoc = mapRole.lastIndexOf(".");
if (lastPeriodLoc > -1) {
mapRole = mapRole.substring(lastPeriodLoc + 1);
}

if (mapRole.equalsIgnoreCase(role)) {
List users = (ArrayList) rpMap.get(nextRole);
if (users.size() > 0){
// role found & populated with one or more users
return true;
}
}
}

// Role not found or no user in role
return false;
}

FYI, here's GeneralUtility.getLocalOid() (which is kind of sloppy... sorry...):

/**
* Windchill may return an oid which includes the server information. This
* information must not be present when looking up objects based on the oid.
* This method searches for any information after a second colon (the
* extraneous information) and removes it.
*
* @param oid the oid to get a local oid for.
* @return a local oid
*/
public static String getLocalOid(String oid) {
if (oid == null)
return null;

if(oid.indexOf("[") == 0 && oid.lastIndexOf("]") == oid.length()-1) oid = oid.substring(1, oid.length() - 1);

int firstColonLocation = oid.indexOf(':');
int lastColonLocation = oid.lastIndexOf(':');
if (lastColonLocation > 0 && lastColonLocation > firstColonLocation)
return oid.substring(0, lastColonLocation);
else
return oid;
}


-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<
AL_ANDERSON
5-Regular Member
(To:Cosmo)

We have a task complete transition that checks that a desired, "mandatory"
role has more than 0 users. If it is empty, then we throw a user-friendly
error instructing that user to assing someone to the mandatory role.

We use this kind of transition logic to check things like this a lot.

Here is a transition that requires that an "Advisor" role be populated
before allowing the user to select that transition. If the user tries to
pick that transition and click "task complete," then they get an error
message.

String rolename = "ASSIGNEDADVISOR";
boolean
isRoleAvailable=com.solar.workflow.WfHelper.areRolePrincipalAvailableFor(((wt.workflow.work.WfAssignedActivity)self.getObject()).getParentProcess(),
(wt.fc.WTObject)primaryBusinessObject, rolename);
if(!isRoleAvailable) {
String msg = "No Users were assigned to the role _NEW_ Change Advisor.
" + "\n Assign a user, then click on Task Complete.";
java.lang.Exception exp = new java.lang.Exception(msg);
throw exp;
}

Al Anderson





Sitanshu Prasad <->
11/14/2011 02:01 PM
Please respond to
Sitanshu Prasad <->


To
-
cc

Subject
[solutions] - RE: Set Up Participants - Role Check




Caterpillar: Confidential Green Retain Until: 12/14/2011



Is there any way to display the alert message on the screen and tell the
user that they haave to mandatorily select the participant?

In Reply to Thomas Busch:
Mike, you could try this:

/**
* Determines if a given role is populated for this specific instance of a
team.
*
* @param role - the name of the role to check against.
* @param teamOid - the obid of the team instance.
* @return true if the role has at least one WTPrincipal in
it, false if not.
* @throws WTException
*/

public static boolean isRolePopulated(String role, String teamOid) {
String localTeamOid = GeneralUtility.getLocalOid(teamOid);
ReferenceFactory rf = new ReferenceFactory();
WTReference ref;
try {
ref = rf.getReference(localTeamOid);
} catch (WTException e) {
log.error("Could not get team from obid " + teamOid + "(local oid: " +
localTeamOid + ")", e);
return false;
}

if (ref == null) {
return false;
}

Team team = (Team) ref.getObject();
if (team == null) {
return false;
}

Map rpMap;
try {
rpMap = team.getRolePrincipalMap();
} catch (WTException e) {
log.error("Could not get RolePrincipalMap from team", e);
return false;
}
String resultOid = null;

Iterator iter = rpMap.keySet().iterator();

while(iter.hasNext()) {
Role nextRole = (Role) iter.next();
String mapRole = nextRole.getStringValue();
int lastPeriodLoc = mapRole.lastIndexOf(".");
if (lastPeriodLoc > -1) {
mapRole = mapRole.substring(lastPeriodLoc + 1);
}

if (mapRole.equalsIgnoreCase(role)) {
List users = (ArrayList) rpMap.get(nextRole);
if (users.size() > 0){
// role found & populated with one or more users
return true;
}
}
}

// Role not found or no user in role
return false;
}

FYI, here's GeneralUtility.getLocalOid() (which is kind of sloppy...
sorry...):

/**
* Windchill may return an oid which includes the server information. This
* information must not be present when looking up objects based on the
oid.
* This method searches for any information after a second colon (the
* extraneous information) and removes it.
*
* @param oid the oid to get a local oid for.
* @return a local oid
*/
public static String getLocalOid(String oid) {
if (oid == null)
return null;

if(oid.indexOf("[") == 0 && oid.lastIndexOf("]") == oid.length()-1) oid =
oid.substring(1, oid.length() - 1);

int firstColonLocation = oid.indexOf(':');
int lastColonLocation = oid.lastIndexOf(':');
if (lastColonLocation > 0 && lastColonLocation > firstColonLocation)
return oid.substring(0, lastColonLocation);
else
return oid;
}


-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<">mailto:tom.busch@stryker.com>
AL_ANDERSON
5-Regular Member
(To:Cosmo)

Sorry. I missed that we had set up a java class for that method. Here is
the method that the workflow calls.

public static boolean areRolePrincipalAvailableFor( WfProcess
wfprocess, WTObject pbo, String role) {
try {
wt.project.Role anyrole =
wt.project.Role.toRole(role);
java.util.Enumeration enumchgown =
wfprocess.getPrincipals(anyrole);
if (enumchgown.hasMoreElements()) {
log.debug(role + " is available \n\n");
return true;
}
log.debug( role + " is unavailable");
} catch (Exception exp) {
exp.printStackTrace();
}
return false;
}


Al Anderson





"Prasad, Sitanshu (GE, Appl & Light)" <->
11/15/2011 06:17 AM
Please respond to
"Prasad, Sitanshu (GE, Appl & Light)" <->


To
"Al X. Anderson" <->
cc
-
Subject
[solutions] - RE: Set Up Participants - Role Check



Announcements

Top Tags