Is there any API method for finding roleId using role name? I get the excel form role name, I need to check if the role name exists or not.
If the role exists
How can I assign this role to a user?
If the role does not exist,
How can I create a role first and then assign this role to the user?
My code
if(role != null && !role.isEmpty()){ Role currentRole=RoleLocalServiceUtil.getRole(companyId,role.trim()); if(currentRole != null) { roleId = currentRole.getRoleId(); } else{ Role newRole = RoleServiceUtil.addRole(role.trim(), null, null, 0); roleId = newRole.getRoleId(); } }
source share