- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:50 PM
Hi everyone,
I have a LDAP transform map to insert/update User records from AD. I need help with a script to not update Samaccountname field when the user is terminated (it may update any other fields if the user is terminated except Samaccountname). Please provide and ideas or script to acheive this scenario.
Thank you in advance,
Karthik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 09:03 PM
Hello @Karthikpasikant
Please change the field mapping for Samaccountname to Script type like the one shown in below screenshot and use the script provided. If you have any different field names or logic to determine terminated accounts change the script accordingly.
answer = (function transformEntry(source, target, action) {
if (action === 'update') {
var ctrl = parseInt(source.u_useraccountcontrol, 10);
ctrl = ctrl.toString(16);
//Check if the user is terminated/disabled, if Yes, don not change the samaccount name
if (source.u_useraccountcontrol == '514' || ctrl.substr(-1) == "2") { //Generally this is how we identify terminated accounts, if you have any other conditions/logic you can use the same here.
return target.u_samaccountname;
}
return source.u_samaccountname;
}
return source.u_samaccountname;
})(source, target, action);
Please mark my answer helpful and accept as solution if it helped you ✔️👍
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 09:02 PM
Assuming the OU for terminated users is different or has different path you can try using something as below
if(source.u_indexOf('terminated')>-1)// Asuming the OU has keyword terminated or so
{ignore=true;}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 12:04 PM
Hi Jaspal,
Thanks for responding. Do I need to add this script in Transform map script or field mapping script? Please suggest.
Thanks,
Karthik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 10:03 PM
how are you determining if user from AD is terminated?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 12:03 PM
Hi Ankur,
When the LDAP schedule runs the data is first stored in the staging table and in that the AD attribute called u_extensionattribute6 stores the status of Terminated/Active/Disabled. So my scenario would be if the AD attribute shows as terminated/disabled then donot update Samacountname else update the Samaccountname with whatever coming from AD samaccount attribute "u_samaccountname".
Thanks,
Karthik