Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to Assign Roles dynamically

Hi Experts,

I created simple GP process with 3 Levels. Every level user i should assign dynamically.

For that i created one input parameter like userId. I mapped this parameter to filled with context parameter option in Block.

I need to start this process from Webdynpro application. My problem is if map UserID in Block means, i am not able to start process. With out mapping i am able to start process, But user is not dynmically.

I am getting Exception like:

com.sap.caf.eu.gp.exception.api.GPEngineException: Role Action4 may not be overwritten during instantiation

I am sending code how i am starting the process

 IGPProcess process = null;

	  try {
		  IWDClientUser wdUser = WDClientUser.getCurrentUser();
		  IUser user = wdUser.getSAPUser(); 
		  wdComponentAPI.getMessageManager().reportSuccess("current user is : " + user.getFirstName());
IGPUserContext userContext = GPContextFactory.getContextManager().createUserContext(user);
 process =GPProcessFactory.getDesigntimeManager().getActiveTemplate(processId,userContext);
		  IGPRuntimeManager rtm = GPProcessFactory.getRuntimeManager();
		  IGPProcessRoleInstanceList roles = rtm.createProcessRoleInstanceList();
		  int rolenum = process.getRoleInfoCount();
IUser dyn_User = UMFactory.getUserFactory().getUserByLogonID(wdContext.currentContextElement().getSel_PA_Name_Element());  //written by hari
		  wdComponentAPI.getMessageManager().reportSuccess("dyn user is : " + dyn_User.getFirstName());
		  IGPProcessRoleInstance roleInstance=null;
		  for (int i = 0; i < rolenum; i++) {
			  
			  if(i==3 || i==1 || i==2){
				 wdComponentAPI.getMessageManager().reportSuccess("Role "+process.getRoleInfo(i).getText()+"  "+process.getRoleInfo(i).getRoleName());
				  roleInstance = roles. createProcessRoleInstance(process.getRoleInfo(i).getRoleName());
				  roleInstance.addUser(dyn_User);
				  roles.addProcessRoleInstance(roleInstance);
			  }
		  }
		  
		  IGPStructure params = null;
		  try {
			  params = GPStructureFactory.getStructure(process.getInputParameters());
			  if (process.getTitle().equals("Accounts Payable Process")) {
				  params.setAttributeValue("BarcodeID_HO2PA2TA", barcode_Id);
				  params.setAttributeValue("UserID_Map_HO2POTA", wdContext.nodePA_Node().getPA_NodeElementAt(wdContext.nodePA_Node().getLeadSelection()).getPA_Name_Elemenet());
				  params.setAttributeValue("UWL_Subject_HO2PA2TL", "Enter Details For Barcode :"+barcode_Id);
			  }
		  }catch(Exception e){
			  wdComponentAPI.getMessageManager().reportSuccess("Exception in Parameter Set "+e);
		  }
		  IGPProcessInstance prInstance = rtm.startProcess(process,barcode_Id,"This process has been started using the GP public API",user,null,params,user);
		
		

	  }
	  catch(Exception e){
		  wdComponentAPI.getMessageManager().reportSuccess("Exception Main Try Block "+e);
	  }

In the above code in If condition i am assigning the 3 role.

 if(i==3 || i==1 || i==2){
				 wdComponentAPI.getMessageManager().reportSuccess("Role "+process.getRoleInfo(i).getText()+"  "+process.getRoleInfo(i).getRoleName());
				  roleInstance = roles. createProcessRoleInstance(process.getRoleInfo(i).getRoleName());
				  roleInstance.addUser(dyn_User);
				  roles.addProcessRoleInstance(roleInstance);
			  }

If i assign 3 roles Exception

com.sap.caf.eu.gp.exception.api.GPEngineException: Role Action4 may not be overwritten during instantiation

If i assign Not 2 roles Exception

com.sap.caf.eu.gp.exception.api.GPEngineException: Enter a role Action4 of role type 2

I need to assign role for initiator only, not for other level.

Please tell any solution to resolve this problem....

Regards,

Sunil

Former Member
Not what you were looking for? View more on this topic or Ask a question