Sample transformation script for AD groups
The text for transformation script (with comments) to get groups for Active Directory instances with a connector is given below.
// The class extends from AbstractGroupTransformScript to inherit its functionality// for performing transformations on groups of dataclass ADGroupSampleTransformationScript extends AbstractGroupTransformScript {// Overrides the execute function in the parent class// The execute function is where the main logic of the transformation script is run@Overrideint execute(LineObject rowObj, Group group) {// Prints a debugging statement indicating that the transformation script has been calledprintln "** - Group Transformation script called."try {// Sets the policy ID for the group to be "4000"group.setPolicyId("4000");// Sets the Metadata Type ID for the group to be "AD_GROUP"group.setMdTypeId("AD_GROUP");// Calls a helper function to populate group object with necessary detailspopulateObject(rowObj, group)} catch (Exception ex) {// Prints the stack trace for any errors that occurex.printStackTrace();// Prints a debugging statement indicating that there was an error in the transformation scriptprintln "** - Transformation script error."// Returns the SKIP constant, which indicates that this row should be skippedreturn SKIP}// Prints a debugging statement indicating that the transformation script has completedprintln "** - Transformation script completed."// Returns the NO_DELETE constant, which indicates that the row was transformed successfullyreturn NO_DELETE}// A helper function to populate a Group object with details from a LineObjectprivate void populateObject(LineObject rowObj, Group group) {// Gets a map of column names to values from the row objectdef columnMap = rowObj.columnMap// If the user is new, sets the group id to nullif (isNewUser) {group.id = null}// Sets the name of the group to the "Name" column in the row objectgroup.name = columnMap.get("Name")?.value// Sets the description of the group to the "description" column in the row objectgroup.description = columnMap.get("description")?.value// If the description of the group is too long, trims it to 254 charactersif (group.getDescription() && group.getDescription().length() > 254) {group.setDescription(group.getDescription().substring(0, 254));}// Sets the status of the group to "ACTIVE"group.status = "ACTIVE"// Adds attributes to the groupaddGroupAttribute(group, "sAMAccountName", columnMap.get("sAMAccountName")?.value);addGroupAttribute(group, "DistinguishedName", columnMap.get("DistinguishedName")?.value);// Sets the scope of the group based on the "groupScope" column in the row objectdef scope = columnMap.get("groupScope")?.valueif (scope) {switch (scope) {case "0":group.setAdGroupScopeId("Domain_Local")breakcase "1":group.setAdGroupScopeId("Global")breakcase "2":group.setAdGroupScopeId("Universal")break}}// Sets the category of the group based on the "groupCategory" column in the row objectdef category = columnMap.get("groupCategory")?.valueif (category) {switch (category) {case "0":group.setAdGroupTypeId("DISTRIBUTION_GROUP")breakcase "1":group.setAdGroupTypeId("SECURITY_GROUP")break}}}// The init function is required by Groovy but is not used in this script// It could be used for setup or initialization tasks if necessary@Overridevoid init() {}}