Transform Map - Active Users only

Vengeful
Mega Sage

I created a transform map to create bulk incidents.

But the user that gets in the incident was the locked out/inactive users.

How can I get the active users?

 

Merza_0-1702884696439.png

 

I have this transform map onBefore script

Merza_1-1702885208067.png

 

 

1 ACCEPTED SOLUTION

SunilKumar_P
Giga Sage

Hi @Vengeful , Open the field mapping and enable the 'Use source script'  check box and try with below script.

 

answer = (function transformEntry(source) {
    var grUsr = new GlideRecord("sys_user");
    grUsr.addActiveQuery();
    grUsr.addQuery('user_name', source.u_user_id); //replace the addQuery as per your data
    grUsr.query();
    if (grUsr.next()) {
        return grUsr.sys_id; // return the value to be put into the target field
    } else {
        return '';
    }
})(source);

 

 

SunilKumar_P_1-1702889043476.png

 

 

 

Regards,

Sunil

 

View solution in original post

7 REPLIES 7

Hi @Vengeful 

Let's check the Use source script checkbox. Below is the sample script to get the Active User.

var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.addQuery('email', source.getValue('u_user')); //replace email by the field corresponding with the value in source. (user_name, name, employee_number, etc);
grUser.query();
if(grUser.next()){
    return grUser.getUniqueValue();
}
return '';

 

Cheers,

Tai Vu

SunilKumar_P
Giga Sage

Hi @Vengeful , Open the field mapping and enable the 'Use source script'  check box and try with below script.

 

answer = (function transformEntry(source) {
    var grUsr = new GlideRecord("sys_user");
    grUsr.addActiveQuery();
    grUsr.addQuery('user_name', source.u_user_id); //replace the addQuery as per your data
    grUsr.query();
    if (grUsr.next()) {
        return grUsr.sys_id; // return the value to be put into the target field
    } else {
        return '';
    }
})(source);

 

 

SunilKumar_P_1-1702889043476.png

 

 

 

Regards,

Sunil

 

@SunilKumar_P 

It worked, thank you