transform_scripts
Table of Contents
Transform Scripts
LDAP Transform
//JWJ0215 2022 // The manager coming in from LDAP is the DN value for the manager. // The line of code below will locate the manager that matches the // DN value and set it into the target record. To ignore the manager // from LDAP, remove or comment out the line: ldapUtils.setManager(source, target); // // NOTE: The 'manager' field SHOULD NOT be mapped in the 'Field Maps' related list // if the manager is brought in through an LDAP import. The 'ldapUtils' scripts // here and in the 'onComplete' Transform Map will map this value automatically. ldapUtils.setManager(source, target); // Set the source LDAP server into the target record target.ldap_server = source.sys_import_set.data_source.ldap_target.server; // Set the u_manager_status boolean if (source.u_extensionattribute11 == '0') { target.u_manager_status = true; } else { target.u_manager_status = false; }
Example
(function transformRow(source, target, map, log, isUpdate) { //Set Last Refreshed On Date to Help Mark Active Groups target.u_last_refreshed_on = gs.nowDateTime(); target.u_active = true; //Convert source timestamp to GlideDateTime target.u_group_created = new ymdLDAP().convertFrom(source.u_whencreated); target.u_group_changed = new ymdLDAP().convertFrom(source.u_whenchanged); //Check if the group is distribution or security var regexDist = new RegExp(/\b(OU=Distribution,OU=Groups)\b/gi); var regexSNow = new RegExp(/\b(OU=ServiceNow,OU=Groups)\b/gi); var regexGal = new RegExp(/\b(OU=GalSync,DC=Universal)\b/gi); var regexSec1 = new RegExp(/\b(OU=Security,OU=Groups)\b/gi); var regexSec2 = new RegExp(/\b(OU=SecurityGroups,DC=Universal)\b/gi); var regexSec3 = new RegExp(/\b(OU=Security Groups)\b/gi); var regexAdmin1 = new RegExp(/\b(OU=Microsoft Exchange Security Groups)\b/gi); var regexAdmin2 = new RegExp(/\b(OU=Administration)\b/gi); var regexAdmin3 = new RegExp(/\b(CN=Builtin)\b/gi); if (regexDist.test(source.u_distinguishedname)) { target.u_group_type = 'distribution'; } else if (regexGal.test(source.u_distinguishedname)) { target.u_group_type = 'legacy'; } else if ((regexSec1.test(source.u_distinguishedname)) || (regexSec2.test(source.u_distinguishedname)) || (regexSec3.test(source.u_distinguishedname))) { target.u_group_type = 'security'; } else if (regexSNow.test(source.u_distinguishedname)) { target.u_group_type = 'servicenow'; } else if ((regexAdmin1.test(source.u_distinguishedname)) || (regexAdmin2.test(source.u_distinguishedname)) || (regexAdmin3.test(source.u_distinguishedname))) { target.u_group_type = 'administration'; } })(source, target, map, log, action==="update");
transform_scripts.txt · Last modified: 12/30/2024 06:54 by johnsonjohn