How to get User's Role using Groovy.

How do I get the user's role? 

I have the user's ID. I'm not sure if there's a method which allows us to get the User's Role. 

.getUserWithProfessionalDetails does not provide the User's role. 

I found another solution. 

In the UI designer for the instantation form, I acquired the value of the Initiator's role_id using the external api

../API/identity/membership?p=0&c=10&f=user_id={{session.user_id}}&d=group_id

If somebody has the groovy solution, it would really help.

Thank you.

Hi,
You can retrieve the user memberships names (same applies if you want roles id) like this:

import org.bonitasoft.engine.identity.UserMembershipCriterion

def memberships = apiAccessor.getIdentityAPI().getUserMemberships(userId, 0, 999, UserMembershipCriterion.ROLE_NAME_ASC)
memberships.roleName.unique() //Returns a list of unique role names for the given userId

HTH
Romain