Help with transform map script to not update specific field

Karthikpasikant
Tera Guru

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

1 ACCEPTED SOLUTION

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);

 

AnveshKumarM_0-1699333346140.png

 

Please mark my answer helpful and accept as solution if it helped you ✔️👍

Thanks,
Anvesh

View solution in original post

13 REPLIES 13

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);

 

AnveshKumarM_0-1699333346140.png

 

Please mark my answer helpful and accept as solution if it helped you ✔️👍

Thanks,
Anvesh

Hi Anvesh,

 

I will give a try with the code you posted and will update this post soon.

 

Thanks,

Karthik

@Karthikpasikant Have you tried this code?

 

As you said you can use u_extensionattribute6 field also to determine if the user is terminated or not in the above code.

Thanks,
Anvesh

Hi Anvesh,

 

I have used your code and modified with our attributes. It worked great. Thank you for all your help.

Here is my code.

answer = (function transformEntry(source) {

        var empStatus = source.u_extensionattribute6;

        if (empStatus == "Terminated" || empStatus == "Disabled") {
            return "";

        }
        return source.u_samaccountname;

})(source);

Jaspal Singh
Mega Patron
Mega Patron

Hi Karthik,

Is the terminated user pulled from same OU as that of Active user from AD?