Transform OnBefore Script to compare source and target fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2017 12:24 PM
I am trying to create an OnBefore transform script to compare fields of the source and target. I have the following script but it is not working
if (source.active == target.active && source.u_ad_samaccountname != target.user_name){
target.u_userid = target.user_name;
target.update();
target.user_name='';
target.update();
}
1. Considering both active fields in source and target are equals to 'true', If source.u_ad_samaccountname is not equals to target.user_name then copy the value of target.user_name field then paste it in target.u_userid field.
2. After 1. is completed it then delete the value of target.user_name field.
Thank you.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2017 12:48 PM
First thing, on a before script, like a before BR, you should not be doing a .update(); I'm not sure if this is your issue.
Add some log statements to check the values going in/being tested.
change lines 2-5 to just
target.u_userid = target.user_name + '';
target.user_name = '';
If those don't resolve it for you, can you provide some more details about what is not working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2017 12:56 PM
Hi Jeffiral,
Please try to add logs and check whether your if condition is getting satisfied or not. If values are correct please write if condition like below and no need to write target.update() two times.
- if ((source.active == target.active) && (source.u_ad_samaccountname != target.user_name)){
- target.u_userid = target.user_name;
- target.user_name='';
- target.update();
- }
Regards,
Sajan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2017 01:31 PM
I tried both of the scripts provided above and they both resulted to this error: "Error during update of sys_user". The issue identified was that the target.user_name had users user_name switched. The soure.u_ad_samaccountname has the correct value but it couldn't update the user_name field as it already has a value in it which was incorrect. That's basically the very problem I am trying to fix, hence, the need to clear out the user_name field.chrismartinsajan0192
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2017 01:40 PM
I feel like there's gotta be something on the sys_user table preventing the update. If you go to the sys_user table and manually change a user_name, do you get any errors there?