Sample code for workgroup creation and fetching workgroup members.

Hi All,

As part of development in SailPoint IIQ, I am giving snippet code for two scenarios. You can use them wherever you require them as part of your needs.

  1. How to create a workgroup using code.

  2. How to fetch the members of the workgroup in which already members are there.

Workgroup Creation:

  import sailpoint.object.Identity;
  import sailpoint.object.Identity.WorkgroupNotificationOption;


  Identity identity = new Identity();
  identity.setName("ADOwners-Workgroup");
  identity.setDisplayName("ADOwners-Workgroup");
  Identity workGroupOwner = context.getObjectByName(Identity.class, "spadmin");
  identity.setOwner(workGroupOwner);
  identity.setWorkgroup(true);
  identity.setNotificationOption(WorkgroupNotificationOption.MembersOnly);
  context.saveObject(identity);
  context.commitTransaction();
  context.decache(identity);

Fetch Members from Workgroup:

  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import sailpoint.api.ObjectUtil;
  import sailpoint.object.Identity;
  import sailpoint.tools.GeneralException;

  List workgroupMembersList = new ArrayList();

  try {
    Identity objectByName = context.getObjectByName(Identity.class, "ADOwners-Workgroup");
    Iterator workgroupMembers = ObjectUtil.getWorkgroupMembers(context, objectByName, null);
    while (workgroupMembers.hasNext()) {
      Object[] object = (Object[]) workgroupMembers.next();
      Identity identity = (Identity) object[0];
      workgroupMembersList.add(identity.getName());
    }
  } catch (GeneralException e) {
    log.error("GeneralException : "+e.getMessage());
  }

  return workgroupMembersList;

If you find out something useful, please like and share it with your friends and colleagues. Happy Learning.:blush:

7 Likes

How do you set the Group Email address?

Jonathan, you can use setEmail method to set group email.
wrkgrpIdentity.setEmail(groupEmail);

2 Likes