Sunteți pe pagina 1din 21

Different Ways of Assigning Users

to a Role

Applies to:
SAP NetWeaver Composition Environment 7.1 SR3 Evaluation Version. For more information, visit the
Composition homepage.

Summary
This article gives an insight to role handling in CAF-GP. It deals with different ways of assigning users to a
GP role and their specific usages.
Author:

Srinivasan Subbiah

Company: HCL Technologies, Chennai, India.


Created on: 4 November 2008

Author Bio
Srinivasan Subbiah is an Application Developer working in HCL Technologies Limited on SAP NetWeaver
Technology (CAF, Web Dynpro for JAVA and GP).

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


1

Different Ways of Assigning Users to a Role

Table of Contents
Introduction .........................................................................................................................................................3
Assigning Users to Default Roles .......................................................................................................................4
Assigning Users Using Initiator Option ...............................................................................................................6
Assigning Users Using Built-in Callable Object ..................................................................................................8
Assigning Users Using Context Parameters ....................................................................................................11
Assigning Users GP API...................................................................................................................................13
Parameter Consolidation and Result State Setting ..........................................................................................17
Testing the Process ..........................................................................................................................................18
Related Content................................................................................................................................................20
Disclaimer and Liability Notice..........................................................................................................................21

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


2

Different Ways of Assigning Users to a Role

Introduction
A process role defines a set of tasks that a user assigned to the role can execute on a process. When we
design a process we will have processor for each action which we may then consolidate to different roles at
block level. At runtime when the process is being executed an instance of type IGPProcessRoleInstance will
be created for each role. When we assign users to that role GPEngine will simply add the user instances to
the corresponding role instances. The above procedure will happen in whatever way we assign the users.
The different ways of assigning users to role include the following.

Assigning users using default roles option in GP design time

Assigning users to role using initiator option and initiation defined option

Assigning users using built-in callable object

Assigning Users using context parameter

Assigning users using GP API

We will design a sample Leave application management process to have a feel of the above prescribed
methods. This process will have four blocks namely

Leave application block

HR Approval block

Manager approval block

Senior management approval block.

Each of them will have separate roles assigned to them. In the first block, the applicant will apply leave. In
the second block, HR can view the number of days of leaves and can approve it. If it is approved, it will go to
the third block for the approval of the manager. He can approve or escalate. If escalated, it will go to the next
block where the senior manager will approve or reject it. We will assign the users to each role in a different
way. For simplicity we are not updating any backend systems. The screen shot provides the detailed
structure of the process.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


3

Different Ways of Assigning Users to a Role

Assigning Users to Default Roles


Whenever we create a process, we will be provided with four roles namely administrator, overseer, owner
and caf_gp_svcuser. Administrator role will provide permissions for maintaining assignments of users to
process roles and to maintain process instances using the GP administration tools. The overseer role allows
the user to view the process instance in the GP runtime and to view all actions in the block. This may help in
monitoring the process flow. Owner role provides permissions to access all steps of the process and to
maintain process instances.
We can assign a default user to these roles. That will ease the process of administrating the process. For
doing this, we should first make the Role Type for these three roles to be Initiation Defined.

Then go to the Default Roles tab.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


4

Different Ways of Assigning Users to a Role

In the Default Roles, we can see the above said three roles to be listed. Click Add Default. Using the Add
Users value help, we can add a user to these roles by clicking Add. Here I am adding Administrator user
for these roles.

This kind of assigning users can be done even after we have activated the process. It should be noted that
this process of assigning default users should be repeated after each time we activate the process (if we edit
the process and then activate again).
If a user owns the process administrator role, he can perform this assignation from GP Administration tab
also.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


5

Different Ways of Assigning Users to a Role

Assigning Users Using Initiator Option


The applicant will enter the number of days he is going to take leave and the details of managers who will
approve it. For achieving this functionality, we will create the Leave Application Block (sequential block). In
this block, create an action Apply Leave AC. This action will have a data input form callable object.

It will have four input fields for getting No. of days of leave(String), HR Ecode (String), Manager Ecode
(String List) and Senior Manager Ecode(String).

Click Next and then Finish.

The above figure shows the structure of the block.


Now for this action a processor will be created which we could see at the block level roles. Now we will
consolidate it to Applicant role.
Click on the Processor of ApplyLeaveAC and then type Applicant in the Consolidate To input area.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


6

Different Ways of Assigning Users to a Role

Click Go button.

Now the leave applicant will be the user who starts this process. So at process level, we will assign initiator
as the user for this role.
Go to the process by clicking on the Leave Management Process.
Select the Roles tab.
Select Applicant role.
In the Role Type dropdown select Initiator.

On doing this type of assignation, whoever is initiating the process will be automatically assigned as the user
for the role Applicant and only he can perform the action of applying the leave.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


7

Different Ways of Assigning Users to a Role

Assigning Users Using Built-in Callable Object


Once the leave is applied, it will go to the HR Manager for approval. He will be displayed the number of days
for which the leave is applied and he can acknowledge it.
We will create the next block HR Approval Block for achieving this. This block will have two actions. One
action will be for assigning the user to the role and the other is for displaying the number of days of leave and
getting approval.
Create the first action with name Assign Users for HR role. Under this action, create a callable object of
built in type Assign Users to Process Role with attributes specified in the figure given below.

Click next.

Here the input parameter is already defined since it is a built-in callable object type. As we can see, it
consists of a structure UserList. Inside it there is another structure called UserItem which is a list. Inside that
there is UserIdentifier. For assigning user to the role, we will map the UniqueId of the user to this
UserIdentifier. If we have a list of UniqueIds then in that case we have to map the structure containing the
uniqueIds to the structure UserItem. It will iterate and assign all the users to the role automatically.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


8

Different Ways of Assigning Users to a Role

We can get the unique id for a user from the api or if we want to test we can get from the UserAdministration
as shown below.

Click next and then finish for creating the callable object.
Next create the second action with name ApprovalHRAC. This will have a data display form callable object.
Create the callable object with the attributes given below in figure.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


9

Different Ways of Assigning Users to a Role

Click Next.
Insert the parameter No. of days. Then click Finish.

Now we will have two processors for this block. We will consolidate these two processors at block level to
one role namely HR Manager. For doing this select the block HRApprovalBlock.
Select the Roles tab.
Press ctrl and select the two processors.
Enter role name HR Manager in the Consolidate to input field and select Go.

Now when we map the input (users unique id) to the Assign user for HR role AC, the built-in callable
object will assign the users to the role of HR Manager. Thus users will be assigned to both the actions.
Note that when we are using this built-in callable object, if we are executing it in a loop and we have different
users in each loop iteration, then the new users will be added to the role but the old users will not be
removed or replaced. In simpler terms this only adds users to the process role instance and will not replace
the existing ones with new ones.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


10

Different Ways of Assigning Users to a Role

Assigning Users Using Context Parameters


In our process, next the control will go to the manager for approval. Here we will assume that there can be
multiple managers for a person. The manager can approve or escalate to senior management. Here it is
assumed that a webdynpro callable object with the following parameters is created by the reader.
Input: UserLogonId--String (Type)--0...n (multiplicity)
Output: Result states: 1.Continue 2.End
The view will have two buttons namely Approve and Escalate. Approve corresponds to the End result state
and Escalate corresponds to Continue. It will not perform any operation with the input parameter.
We have to create the block Manager Approval Block and the action Manager Approval AC. Then we
have to insert the created webdynpro callable object Manager Approval CO.
The structure of the block will look like the following figure.

Now we will have to assign users to the role. Select the block and go to Roles tab.
Select the Processor of Manager Approval.
Click on the Filled from Context Parameter dropdown.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


11

Different Ways of Assigning Users to a Role

Select the UserLogonId.

Now we have assigned the context parameter UserLogonId to the role. Note that this attribute should be a
valid login id of a portal account.

This method of assigning users to a role will replace the existing users for the role with the new users. We
can also assign multiple users this way. So it can be used when we need to execute some looping actions
with different users assigned as processors each time. After doing this kind of assignation, this role will not
be visible at process level.
Note the major disadvantage with this kind of assignment is that we cannot consolidate multiple processors
to a single role and then perform this assignation. This type of assigning users is limited to the processors of
action alone (action alone). It also mandates that the action should have the logonId as a mandatory
parameter.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


12

Different Ways of Assigning Users to a Role

Assigning Users GP API


When the manager escalates, it will go to the senior manager for his approval. Here we will have a block
named Senior Management Approval which contains two actions, Role Assigning Custom AC and
Senior Management Approval AC. Here we will assign user to the role exactly similar to the way we did
with assigning users with built-in callable object, except that here we will create the java class for the callable
object ourselves.
We will have a background callable object for the first action. For creating a background callable object
please refer to Implementing a background callable object.
This background callable object will take a String input SeniorManager. It will have a result state Success.
The getDescription method will have the following code

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


13

Different Ways of Assigning Users to a Role

The execute() will have the following code.

In the execute method, we are getting the input parameter which will be a valid logon id via SeniorManager
parameter. Then we will get the IUser instance of the portal user with that logon id. This is done via the code

As described earlier, a ProcessRoleInstance would have been created for the role corresponding to this
role. We have to retrieve this role instance and add our IUser (user) to it for assigning a user to this role. We
can retrieve the ProcessRoleInstance using the following code.

Then we have to add the runtime defined user which we retrieved previously to this role instance via the following code.

The other way of achieving the same is using the GPRuntimeManager.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


14

Different Ways of Assigning Users to a Role

Here we will use the GPRuntimeManagers addRuntimeDefinedUserToRole() which will take the process
instance, role name, iuser instance of the user we want to assign and the user context of that user. We can
get the process role instance using the design time id of the process which we can get from GP design time
as shown below.

The second action will have a decision dialog callable object with name Approval and with following
attributes.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


15

Different Ways of Assigning Users to a Role

Click next, next and enter the message and button details.

Click next and finish.


Now we will go to block level roles and consolidate the processors of these two actions to the role Senior
Manager as given below.

Now during the process flow, our background callable object will assign the user to the role Senior Manager.
The main advantage of using the GP API can be felt when we already have some logic to be implemented
via a background callable object. We can just have our role assigning code embedded along with the logic.
In that case, we can avoid having a separate built-in callable object and hence an action for just assigning
users to a role. That will improve the performance.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


16

Different Ways of Assigning Users to a Role

Parameter Consolidation and Result State Setting


Now having formed the process, we have to do parameter consolidation.
Go to process level by selecting Leave Management Process.
Select Parameters tab.
We have to map the No. of Days of Leave Application BlocK to No. of Days of HR Approval Block.
Press ctrl and select both of them and click Group. Give the Name as No. of Days and click Create.

Similarly, map the following:


1.HR Ecode (Leave Application Block) and UserIdentifier (HR Approval Block : UserList. : UserItem.) as
HRUserIdentifier
2. Manager Ecode (Leave Application Block) and UserLogonId (Manager Approval Block) as
ManagerUserLogonId
3. Senior Manager Ecode(Leave Application Block) and SeniorManager (Senior Management Approval) as
SeniorManager.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


17

Different Ways of Assigning Users to a Role

Then check whether the HR Role and Senior Manager are of type Runtime Defined.
We have to set the result states for getting the proper flow. Go to Manager Approval Block.
Select the Manager Approval AC. Select the Result States.
Set target for result state End to be Terminal.
Set target for result state Continue to be Senior Management Approval AC (Senior Management
Approval).

Testing the Process


Now activate the process and set the default roles as specified in the Assigning users to Default Roles
section.
Now I am taking 4 portal users for testing with the following details.
User Name

LogonId

UniqueID

Description

Leave
Applicant

L181641

HR Manager

H181641

Manager

M181641

Manager who will


escalate or reject

Senior
Manager

S181641

Senior manager for


approving

The user who applies


leave
USER.PRIVATE_DATASOURCE.un
:H181641

HR manager

Now with Leave Applicant user, we will initiate the process since Applicants role type is Initiator. Now we
will see the input page for Leave Applicant user.

Note: we have to give uniqueId for HR Manager as we are using the built-in callable object for assigning the users to the
role. For Manager Ecode and Senior manager Ecode, we can give the logonId.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


18

Different Ways of Assigning Users to a Role

Click Submit.
It will go to the next user, HR Manager. In HR Managers GP Runtime, we can see the work item in the
pending tasks. Select it.

Now he can see the number of days for which leave is applied. Click Ok.
Now we will go to the pending actions of the Manager and open the work item.

We will click on Escalate.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


19

Different Ways of Assigning Users to a Role

Now the control will go to the senior manager. Open the pending work item in the Senior Manager login.

Click Approve or Reject. With that the process will be terminated.

Related Content
For information on default process roles please refer to Process Roles
For information on creating webdynpro callable objects please refer to Implementing webdynpro callable
object
For more information, visit the Composition homepage.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


20

Different Ways of Assigning Users to a Role

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not
supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document,
and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or
code sample, including any liability resulting from incompatibility between the content within this document and the materials and
services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this
document.

SAP COMMUNITY NETWORK


2008 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com


21

S-ar putea să vă placă și