Skip to Content

Hello there,

In this blog we will have a quick review on how to create and assign custom roles in SAP Cloud Platform Portal and Fiori Launchpad Portal. We will also cover how to access this roles from a SAPUI5 / Fiori app.

Creating and assigning a user role

First, we should go to the service Portal overview page inside SAP Cloud Platform. In this page, we should make click on the Configure Portal option.

From the Roles section, we can go and create a new Custom role. In this case, it will be called Test_Role.

Once that we have created the role, we will assign a user to this role. We can do so by making click on the Assign option after selecting the new created role.

Now, we will have both the role and the user ready for the next step.

Next, we will need to enter our SAP Fiori Launchpad site, inside the portal service.

In the configuration cockpit, we should go to Roles, under the Content Management section. There, we should create the same role we created on the Portal configuration.

We must be careful of setting the Role ID with the same name as our previously created role.

We can now assign Catalogs and groups as required for this new role.

 

Accessing roles from a SAPUI5 app

To access the roles for a user we can include the following code inside our Component.js init method.

try{
			
  jQuery.sap.require("sap.ushell.cpv2.services.cloudServices.SiteService");

}catch(oException){
		
}

This will help us ensure we have the SiteService component loaded.

Next, we can create a SiteService object where we need to access the roles. In this example, the object is created inside the CreateContent method of the view.

        try {
            if (sap.ushell && sap.ushell.cpv2 && sap.ushell.cpv2.services && sap.ushell.cpv2.services.cloudServices && sap.ushell.cpv2.services.cloudServices.SiteService) {

                var oLocalSiteService = sap.ushell.cpv2.services.cloudServices.SiteService();
                var oRoles = oLocalSiteService.siteModel.getProperty("/roles");
                var oProperty;


                for (oProperty in oRoles) {

                    if (oRoles.hasOwnProperty(oProperty)) {
                        if (oProperty.toString() === "Test_Role"{
				/// Some action based on the Test_Role
                        }
                    }
                }


            }
        } catch (oException) {

        }

As you can see, we are able to access the user configured roles from this object. Next we could specify some defined behavior based on the user role.

 

I hope this blog might be helpful.

 

Thank you!

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. EDGAR ADRIAN MARTINEZ ARCE Post author

    Hi Raghavendra,

    You would normally find the portal service inside the Services tab of your Account (for trial accounts) or Subaccount (on productive cloud instances).

    If it is not enabled, you could make click on the service, then click the Enable button on the next screen.

    Please let me know if this procedure is useful, in case it is not, please share a screenshot and more details on your account type (no passwords or usernames are necessary).

    Thank you!

    Best Regards!

    Edgar.

    (0) 
  2. Former Member

    Hello Edgar,

     

    Thanks for the very nice blog!!

     

    We have requirement wherein we need to change a role of a user i.e from role A to role B from our custom SAPUI5 app.

    Wanted to understand if this update operation is possible to achieve or can we only do a read of roles from SAPUI5 app.

     

    Thanks is advance!!

     

    Regards,

    Jigar Salecha

    (0) 
  3. Ankit Verma
    Hello,
    I got the same requirement to fetch the custom roles and I am using below code to load the site services
    try{

    jQuery.sap.require(“sap.ushell.cpv2.services.cloudServices.SiteService”);

    }catch(oException){

    } but I am getting an exception: “failed to load ‘sap/ushell/cpv2/services/cloudServices/SiteService.js’ from ../../resources/sap/ushell/cpv2/services/cloudServices/SiteService.js”

    I have also added the bootstrap code:

    <script src=”../resources/sap/ushell_abap/bootstrap/abap.js”></script>

    but still cpv2 service is not availbable.

    Is this CPV2 service depends upon the Launchpad version or HANA cloud version? if not then how can I fix this error or is there any other way to fetch the roles?

    (1) 

Leave a Reply