The following code shows how to use the API service to create, read, update, and delete single users using the IUser interface:

define variable usr as IUser no-undo.

usr = service:NewUser("MyUser@MyDomain").
/* Set properties */
. . .
service:CreateUser(usr).

. . .
usr = service:GetUser("MyUser@MyDomain").
/* Set properties */
. . .
service:UpdateUser(usr).

. . .
service:DeleteUser("MyUser@MyDomain").

It is also possible to retrieve a collection of users in the database from the service and then do create, read, update, and delete on users in the IUserSet collection before passing the collection to the service to be committed in a single transaction:

define variable userSet as IUserSet no-undo.

userSet = service:GetUsers().

usr = service:NewUser("Fred@ABCDomain").
/* Set properties */
. . .
userSet:Add(usr).

usr = userSet:Find("Admin").
usr:Description = "The Admin user for the default domain.".

usr = userSet:Find("Fred ").
userSet:Remove(usr).

service:UpdateUsers(userSet).

Users can also be created, read, updated, and deleted in a similar manner on the Users property collection available on the IDomain interface. When creating a new IUser to add to the IDomain Users collection the user name should be passed to the constructor without the @domain qualifier, as follows:

domain = service:GetDomain("ZZDomain"):
users = domain:Users().

user = service:NewUser("John").
/* Set properties */
. . .
users:Add(user).

service:UpdateDomain(domain).

For more information on the: