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

How can we select the approver group based on the attribute value in the workflow?

CH_10078393
6-Contributor

How can we select the approver group based on the attribute value in the workflow?

How can we select the approver group based on the attribute value in the workflow?

1 REPLY 1

Hi @CH_10078393 

If you have just few groups, then you can create the tasks for each group, and check the attribute and route the flow to right task with right group. based on your conditions

 

wt.change2.WTChangeIssue thisIssue = (wt.change2.WTChangeIssue)primaryBusinessObject;
com.ptc.core.lwc.server.LWCNormalizedObject obj = new
com.ptc.core.lwc.server.LWCNormalizedObject(thisIssue,null,null,null);
obj.load("PRODUCT_CATEGORY");
Object categoryValue = obj.get("PRODUCT_CATEGORY").toString();
System.out.println("Value of product category: " +categoryValue );
if (categoryValue.equals("A1"))	{
	System.out.println("Setting result to A1");
	result="A1";
}
else {
	if (categoryValue.equals("A2"))	{
	System.out.println("Setting result to A2");
	result="A2";
	}
	else {
		System.out.println("Setting result to A3");
		result="A3";
	}
}

 

here is a code how to fill the role from a group .

 

String targetOrgName="ORG";
wt.inf.container.OrgContainer org=null;
try{
	// WF USAGE in wf robot// 
	wt.workflow.engine.WfProcess wfprocess = ((wt.workflow.engine.WfProcess)self.getObject());
	// usage in a Task WF // wt.workflow.engine.WfProcess wfprocess = (((wt.workflow.work.WfAssignedActivity)self.getObject()).getParentProcess());
	wt.team.Team updateTeam = wt.team.TeamHelper.service.getTeam(wfprocess);
	java.util.Enumeration roles = wfprocess.getRoles();
	String listofroles = new String();
	Integer counterRole = 0;
	while (roles.hasMoreElements()){
		wt.project.Role role = (wt.project.Role)roles.nextElement();
		java.util.Enumeration participants = wfprocess.getPrincipals(role);
			// check display role name 
		if (!(participants.hasMoreElements())){
			// display ROLE name
			if (role.getDisplay().equalsIgnoreCase("Promoter")){
				System.out.println("-------------------------------");
				System.out.println("Role found: " + role.getDisplay());
				System.out.println("-------------------------------");
				java.util.Enumeration orgs=wt.org.OrganizationServicesHelper.manager.findLikeOrganizations(
					wt.org.WTOrganization.NAME,
					targetOrgName,
					((wt.inf.container.ExchangeContainer) wt.inf.container.WTContainerHelper.getExchangeRef().getContainer()).getContextProvider());
				wt.org.WTOrganization targetOrg = null;
				if (orgs.hasMoreElements()){
					targetOrg = (wt.org.WTOrganization) orgs.nextElement();
					org = wt.inf.container.WTContainerHelper.service.getOrgContainer(targetOrg);
				}
				wt.org.DirectoryContextProvider dcp = wt.inf.container.WTContainerHelper.service.getPublicContextProvider(org,wt.org.WTGroup.class);
				java.util.Enumeration groups=wt.org.OrganizationServicesHelper.manager.getGroups("*", dcp);
				while (groups.hasMoreElements()){
					wt.org.WTGroup group=(wt.org.WTGroup) groups.nextElement();
					// group name definition
					if (group.getName().equalsIgnoreCase("GROUPNAME")) {
						System.out.println("-------Message from WF Problem Report" + " |" + wfprocess .getName() + "|----------");
						System.out.println("User added from group="+group.getName());
						java.util.Enumeration grmembers = wt.org.OrganizationServicesHelper.manager.members(group, false);   
						while(grmembers.hasMoreElements()){
							wt.org.WTPrincipal addedmember = (wt.org.WTPrincipal)grmembers.nextElement();
							//internal role name where are the users added from the group 
							wt.team.TeamHelper.service.addRolePrincipalMap(wt.project.Role.toRole("PROMOTER"), addedmember , (wt.team.WTRoleHolder2) updateTeam);
							System.out.println("Name of added User :: "+addedmember.getName());
						}
					}

				}
			}
		}
	}
}
catch(Exception _e){
	wt.workflow.engine.WfProcess wfp = ((wt.workflow.engine.WfProcess)self.getObject());
	System.out.println("WF Name:"+wfp.getName()+"findGroupsTest() ie:\n"+_e);
}

 

PetrH

Announcements

Top Tags