On one of my recent SRM projects I had a requirement wherein a specific portal role was to be assigned to a portal user based on an action performed on one of the standard SRM webdynpro screen. The assigned role was also to be removed based on another action. Probably there could be some help available on SDN, but I was unable to find it. So thought of sharing this. Hope it helps some.....
SAP has provided a service wrapper interface /sapsrm/if_spml_srvc_wrapper with methods that help carry out operations on a portal user ID. I have shown below how a user can be assigned a specific portal role, y'all can try other methods available to create a portal user, delete one, delete roles and so on...
To assign a portal role we need to get the unique ID of the role which your portal administrator could provide you.
CONSTANTS:
*RFC Destination of portal in SM59
lc_rfcdest TYPE rfcdest VALUE 'PORTAL',
*Portal user ID
lc_portal_user TYPE xubname VALUE 'TEST_USER',
*Unique ID of the portal role
lc_portal_role TYPE txt255 VALUE 'ROLE.PCD_ROLE_PERSISTENCE.EIuf/fYAf+G39przMn+8lcKhzII='.
DATA:
lo_spml_wrpr TYPE REF TO /sapsrm/if_spml_srvc_wrapper,
lt_ep_roles TYPE /sapsrm/t_ep_roles,
ls_ep_roles TYPE /sapsrm/s_ep_roles.
lo_spml_wrpr = /sapsrm/cl_spml_wrpr_factory=>get_spml_wrapper( lc_rfcdest ).
ls_ep_roles-uniqueid = lc_portal_role.
APPEND ls_ep_roles TO lt_ep_roles.
TRY.
lo_spml_wrpr->add_role_ume_user(
EXPORTING
iv_logon_id = lc_portal_user
it_roles = lt_ep_roles ).
CATCH /sapsrm/cx_spml_connection.
"Exception handling here
CATCH /sapsrm/cx_spml_service.
"Exception handling here
ENDTRY.
Best regards
Vipin Varghese