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

Getting the process from an activity

RFS
11-Garnet
11-Garnet

Getting the process from an activity

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?

 

ACCEPTED SOLUTION

Accepted Solutions
RFS
11-Garnet
11-Garnet
(To:RFS)

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.

View solution in original post

5 REPLIES 5
avillanueva
22-Sapphire II
(To:RFS)

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;

    }
RandyJones
19-Tanzanite
(To:RFS)

You can use the getParentProcess() method of a WfAssignedActivity.

 

https://www.ptc.com/en/support/article/CS82856

 

 

avillanueva
22-Sapphire II
(To:RandyJones)

I think I read that backwards. Going from the WfAssignedActivity to the Process not the other way around.

HelesicPetr
22-Sapphire I
(To:RFS)

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

RFS
11-Garnet
11-Garnet
(To:RFS)

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.

Announcements

Top Tags