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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Assigning workflow tasks to roles

smcvr
15-Moonstone

Assigning workflow tasks to roles

I want to send a task to the manager of that department according to the selected department. Is there any way I can assign this user directly without getting it from the form?

ACCEPTED SOLUTION

Accepted Solutions
HelesicPetr
22-Sapphire I
(To:smcvr)

Hi @smcvr 

If you solve the mapping what user is in the selected department you can find a user and assign him to a workflow role and the role use in the task,

 

you need to find a team and a role from a object the workflow is related

Add the participant(user) to the role. 

example from Change Task object

HelesicPetr_0-1672989782316.png

 

generally example API to add a participant to a role is > 

wt.project.Role teamRole = wt.project.Role.toRole(roleName); // roleName is a internal name of role what you want to update
wt.org.WTPrincipalReference princRef = null; // you need to find your user and get WTPrincipal object in my case I have a WTPrincipalReference and from this object I fet WTPrincipal -  just for explanation PS: WTPrincipal is a root type of WTUser
wt.maturity.PromotionNotice targetObject = (wt.maturity.PromotionNotice)primaryBussinessObject; // from workflow primaryBussinessObject can be any Change Object Promotion, ChangeRequest, Activity, Notice 

wt.team.Team team = (wt.team.Team) targetObject.getTeamId().getObject();
wt.team.TeamHelper.service.addRolePrincipalMap(teamRole, princRef.getPrincipal(), team);

 Adding user to a role has to be done before a workflow task is run.

 

Hope this explanation can help

 

PetrH

View solution in original post

5 REPLIES 5
HelesicPetr
22-Sapphire I
(To:smcvr)

Hi @smcvr 

If you solve the mapping what user is in the selected department you can find a user and assign him to a workflow role and the role use in the task,

 

you need to find a team and a role from a object the workflow is related

Add the participant(user) to the role. 

example from Change Task object

HelesicPetr_0-1672989782316.png

 

generally example API to add a participant to a role is > 

wt.project.Role teamRole = wt.project.Role.toRole(roleName); // roleName is a internal name of role what you want to update
wt.org.WTPrincipalReference princRef = null; // you need to find your user and get WTPrincipal object in my case I have a WTPrincipalReference and from this object I fet WTPrincipal -  just for explanation PS: WTPrincipal is a root type of WTUser
wt.maturity.PromotionNotice targetObject = (wt.maturity.PromotionNotice)primaryBussinessObject; // from workflow primaryBussinessObject can be any Change Object Promotion, ChangeRequest, Activity, Notice 

wt.team.Team team = (wt.team.Team) targetObject.getTeamId().getObject();
wt.team.TeamHelper.service.addRolePrincipalMap(teamRole, princRef.getPrincipal(), team);

 Adding user to a role has to be done before a workflow task is run.

 

Hope this explanation can help

 

PetrH

smcvr
15-Moonstone
(To:HelesicPetr)

How can I get the WTPrincipal object?

 

HelesicPetr
22-Sapphire I
(To:smcvr)

Hi @smcvr 

for example 

 

 

String userName ="admin";
WTUser wtUser = null; //WTUser is subClass of WTPrincipal
		try
		{
			QuerySpec queryspec;
			queryspec = new QuerySpec();
			int wtUserObjectInt = queryspec.appendClassList(WTUser.class, true);

			CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);
			andCondition.append(new SearchCondition(WTUser.class, WTUser.NAME, SearchCondition.LIKE, userName), new int[]{wtUserObjectInt});

			queryspec.appendWhere(andCondition, new int[]{wtUserObjectInt, wtUserObjectInt});

			QueryResult resultQuery = PersistenceHelper.manager.find((StatementSpec) queryspec);

			if (resultQuery.hasMoreElements())
			{
				Object obj[] = (Object[]) resultQuery.nextElement();

				wtUser = (WTUser) obj[0];
			}
		} catch (WTException e)
		{
			e.printStackTrace();
		}

 

 

 

PetrH

smcvr
15-Moonstone
(To:HelesicPetr)

I couldn't do it I'm getting a Check Syntax error

HelesicPetr
22-Sapphire I
(To:smcvr)

Hi @smcvr 

It is normal. The code I provided is not ready for workflow expresion.

Correct all syntax errors.

 

You need to complete all types with full qualified class names

 

For example 

Object should be withen as java.lang.Object or QueryResult  as wt.fc.QueryResult and so on.

 

PetrH

Announcements


Top Tags