Skip to Content
Technical Articles
Author's profile photo Shreshtt Bhatt

SAP Commerce | Export only UserGroup & Employee Access Rights

SAP Commerce has Special Logic written to Export Access Rights available in the System. The below script is responsible for Exporting Access Rights –

"#% impex.setTargetFile(""UserRight.csv"",true,0,0);"
#SPECIAL CASE: Type UserRight will be exported with special logic (without header definition), see
"#% impex.exportItems(""UserRight"", false);"

Problem Statement:

Since this special logic export access rights of all the UserGroups & Users including its child items as well such as B2BUnit, Employee, Customer, B2BCustomer etc.

In Production System, there can be millions of B2BUnits and Customers are available which makes the whole Export Script drastically Slow to provide the final result.

Generally Access Rights relevant for UserGroup & Employee only then there is no point of looking these irrelevant items as well and to make the whole Export Process Slow.

What if i only Export Access Rights of UserGroup & Employee only, will that make if Fast, and the answer if YES 🙂

Special Logic:

Before we jump to the Solution, let’s first understand what this Special Logic is and where it is written.

Exporter Class –

package de.hybris.platform.impex.jalo.exp;

public class Exporter implements LocationProvider {

public void exportItems(String typecode, int count, boolean inclSubTypes) throws ImpExException 
      if (typecode.equals(TypeManager.getInstance().getComposedType(UserRight.class).getCode())) 
          this.exportUserRights(); //Special Logic
         int start = 0;
         int range = count;
         Collection items = null;

          do {
             items = this.getAllItems(typecode, start, range, inclSubTypes);
             start += range;
          } while(items != null && items.size() == range);

Whenever we Export UserRights, this if condition matched, and exportUserRights() method is being called. This method uses one Helper class – ImportExportUserRightsHelper which ultimately export the permissions.

ImportExportUserRightsHelper – 

public void exportSecurity() 
    Set allUserAndUserGroups = new HashSet();
    allUserAndUserGroups.addAll(UserManager.getInstance().getAllUserGroups()); //Fetch all UserGroups including child one as well
    allUserAndUserGroups.addAll(UserManager.getInstance().getAllUsers()); //Fetch all users including child one as well

This method fetches all UserGroups & Users including its child items as well.

We are interested in Export Access Rights of only UserGroups & Employees without any child items.



The Solution is pretty simple. This can be achieved using Personalization (or SearchRestriction).

Step 1- 

Create new Backoffice Role e.g. SecurityGroup which should have Access of Export Permission in Backoffice.


Step 2-

Create Two new SearchRestriction for our newly created Backoffice Role e.g. SecurityGroup

INSERT_UPDATE SearchRestriction;code[unique=true];name[lang=en];query;principal(UID);restrictedType(code);active;generate

;Export_UserGroup_Permission_Restriction;Restrict SecurityGroup to export only UserGroup Permissions;{itemtype} in ({{select {PK} from {ComposedType} where {code}='UserGroup'}});SecurityGroup;UserGroup;true;true

;Export_Employee_Permission_Restriction;Restrict SecurityGroup to export only Employee Permissions;{itemtype} in ({{select {PK} from {ComposedType} where {code}='Employee'}});SecurityGroup;User;true;true

The first one will apply on UserGroup and another one on User Type and filter query make sure only item with UserGroup and Employee ComposedType shall be considered.

Step 3-

Now create any test employee e.g. testSecurityGroup for SecurityGroup role and login with that employee in Backoffice.


Step 4-

Click on Export node, one popup window shall be open. Paste UserRights export script there.


Step 5-

Validate the script and click on Save button. As soon as we save the script, a new Impex Media created for the same. Select Mode – Export (No re-import)


Step 6-

Click on Next button and Start the Export



This way we can improve the Performance of Exporting UserRights in Production and get the meaningful result as we want.


Thank You

Shreshtt Bhatt

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Vivek Dewangan
      Vivek Dewangan

      Hi Shreshtt Bhatt,

      I wants to know how I can set the search restrictions so that I can fetch the userrights for specific Usergroups only. I don't want to fetch all usergroups.

      My Requirement - Need to fetch UserRights for 5 Usergroups like below

      applicationsupport, accountrepresentative, replenishmentagent, customerservice

      There are 4 different user groups in my application, I want to fetch the userrights data only for the above usergroups.

      Could you please suggest some solution.