Advanced Techniques - User management with Groovy

Create user

New users can be created and added to a user group via a process. A Groovy script action takes care of the adding with the following script:
def user = g_om.createUser{
	container     = "System"
	name          = "user-${now().withoutFractionalSeconds}"
	loginName     = "UserU-${now().withoutFractionalSeconds}"
	emailBiz      = "user@example.org"
	description   = "User created with Groovy at ${now().withoutFractionalSeconds}"
    memberOf    = ["User", "6AA80844C3F99EF93BF4598EB18605BF86FDD3C5"]
}
The access object "g_om" provides a structure that enables you to execute operations in the user management and organizational structure of a portal. When a user is created in this example, the following properties will be set, of which "name" and "loginName" are mandatory. All of the other properties are optional. A time stamp is used to ensure the uniqueness of the user name and login ID. If, in the user management, the uniqueness of the user name and login ID is not guaranteed by the ID or a timestamp, but instead uses a different format, such as first name.last name, then a check must be run to ascertain whether a user with the same data exists already, and, if necessary, runs an appropriate error handler.

Read user's memberships

The following script can be used to determine the group memberships of a user.
def user = g_om.getUser(g_session.user.guid)
def sets = g_om.getMembershipSets(user)
def strAdminGroupGuid = "EF16F15EDA8562E19D7DD75BF2OP3001F119193C"

if (sets*.guid.contains(strAdminGroupGuid))
	return adminGroupMemberTrue
else
	return adminGroupMemberFalse
In this example, the GUID of the current logged-in user will be read with the help of "g_session.user.guid". "g_om.getMembershipSets(member)" returns a list with all groups - including subordinate groups - that the defined user is a member of. Subsequently, using an iteration through the GUIDs of the identified groups, it is possible to establish if the GUID of the "Administrators" group is included in the results. Dependent on this evaluation (in this example, the evaluation of whether the user is a member of the "Administrators" group) a corresponding value will be returned, with which, for example, when this code is used in a Groovy filter condition, subsequent steps in the workflow can be precisely controlled.