Transform Script to Change value for specific users

David Casper
Tera Guru

I have a scheduled data import, using a transform map, to import our users no a daily basis. One of the included fields is 'Enabled' (source) to update the 'Active' (target) field in ServiceNow.

The need is to have a script that looks for a handful of users and changes the Enabled or Active value for them, but only them. I'm a beginner when it comes to programming and have found that this could be done with a onBefore script or maybe a source script.

Latest test is with an onBefore which is allowing the transform to run, but the value is not changing. 

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

if(source.login == 'nhesgz');
target.active = false;

})(source, map, log, target);

 

Looking for the best way to do this. Any and all suggestions are welcome. 

1 ACCEPTED SOLUTION

okay, so when we run the script in transform map it run for each row and it will check if source.u_login matches and then it will update at run time. 

 

onComplete() will run once when all the transformations are done for all the records (even after for the user which we wanted to set as inactive) and then it will make those users inactive. 

 

I believe using transform map is better option since you will be checking the u_login user at run time for each row transform, and would taking action right away, instead of using onComplete() with GlideRecord query which will try to glide the sys_user table everytime for every specific records.

View solution in original post

34 REPLIES 34

SanjivMeher
Kilo Patron
Kilo Patron

What are you storing in source.login. Is it the correct parameter in the source? Can you use this and let me know, what you see in the system log

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

gs.log('++++++++source.login+++++++++++'+source.login);

if(source.login == 'nhesgz');
target.active = false;

})(source, map, log, target);


Please mark this response as correct or helpful if it assisted you with your question.

The source.login field is the users's AD login which maps to the user_name field. 

 

Here is the log output from Script Log Statements.

 

find_real_file.png

I believe it should be u_login

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(source.u_login == 'nhesgz') // Here we don't need semi-colon (;) as you have in your script.
target.active = false;
})(source, map, log, target);

Definitely a good catch!!! Unfortunately I'm getting the same error in the log as I posted above. 

 

Here is my current script.

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
gs.log('++++++++source.login+++++++++++'+source.login);
if(source.u_login == 'nhesgz')
target.active = false;

})(source, map, log, target);