Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
I am trying to write some script that checks to see if a Setup Role has members before continuing. I have script that works in a Condition operation and now I am trying to add it to execute on the Complete Task transition. For this to work, I need to use the 'self' object of the activity and get to the workflow process object... but the Javadocs aren't entirely complete and I can't find the correct documentation on the activity (WfAssignedActivity?) class. Does anyone have this info?
Solved! Go to Solution.
Following up on research... eventually I found a different Javadoc source that had the documentation on WfAssignedActivity and the getParentProcess method that did the trick for me. It is still annoying that the supplied Javadoc from PTC didn't have the WfAssignedActivity class listed at all.
Maybe this snippet from my old code will help:
private static WfAssignedActivity getActivityByName(WfProcess process, String activityName) throws WTException
{
LOGGER.debug("In getApprovalAssignment()");
QuerySpec querySpec= new QuerySpec(WfAssignedActivity.class);
SearchCondition condition1=new SearchCondition(WfAssignedActivity.class, "parentProcessRef.key", SearchCondition.EQUAL, PersistenceHelper.getObjectIdentifier(process));
querySpec.appendWhere(condition1, 0);
QueryResult result=PersistenceServerHelper.manager.query(querySpec);
LOGGER.debug("Found " + result.size() + " activities related to process.");
while (result.hasMoreElements())
{
WfAssignedActivity tempActivity=(WfAssignedActivity)(result.nextElement());
LOGGER.debug("Activity Name: " + tempActivity.getName());
if (tempActivity.getName().equals(activityName))
return tempActivity;
}
return null;
}
You can use the getParentProcess() method of a WfAssignedActivity.
https://www.ptc.com/en/support/article/CS82856
I think I read that backwards. Going from the WfAssignedActivity to the Process not the other way around.
Hi @RFS
Here is example how to control that role do not contains actual user that complete the task.
Change name of role as you need
this example use "APPROVER" as checked role.
wt.workflow.engine.WfProcess wfprocess = (((wt.workflow.work.WfAssignedActivity) self.getObject()).getParentProcess());
java.util.Enumeration roles = wfprocess.getRoles();
while (roles.hasMoreElements())
{
wt.project.Role role = (wt.project.Role) roles.nextElement();
java.util.Enumeration participants = wfprocess.getPrincipals(role);
// kontrola zobrazovaného názvu role
if (role.getDisplay().equalsIgnoreCase("APPROVER"))
{
wt.org.WTPrincipal activeUser = wt.session.SessionHelper.getPrincipal();
if (!participants.hasMoreElements())
{
String msg = "Approver MUST be assigned";
java.lang.Exception exp = new java.lang.Exception(msg);
throw exp;
}
while (participants.hasMoreElements())
{
wt.org.WTPrincipalReference principal = (wt.org.WTPrincipalReference)participants.nextElement();
wt.org.WTPrincipal assignedUser = principal.getPrincipal();
if (assignedUser.getName().equals(activeUser.getName()))
{
String msg = "Can not set yorself as Approver.";
java.lang.Exception exp = new java.lang.Exception(msg);
throw exp;
}
}
}
}
Here is an old post where is interesting discussion
Stop-user-from-adding-self-to-Setup-Participant-role
PetrH
Following up on research... eventually I found a different Javadoc source that had the documentation on WfAssignedActivity and the getParentProcess method that did the trick for me. It is still annoying that the supplied Javadoc from PTC didn't have the WfAssignedActivity class listed at all.