OnBefore Transform Script - DONOT Insert/update records on condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 01:10 AM
Dear Team,
I have a requirement for onbefore transform script which is working partially-
Condition is
If Manager (u_manager : source) starts with 'xt' OR 'XT' & Manager (manager : target-sys_user table) then ignore the insert/update of those records in target table.
Below is the onbefore transform Script I wrote
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var sourceMgr = source.getValue('u_manager');
var targetMgr = target.getValue('manager');
if ((targetMgr != "") && (sourceMgr.indexOf('XT') >= 0 || sourceMgr.indexOf('xt') >= 0)) {
ignore = true;
} else
ignore = false;
})(source, map, log, target);
But after loading the below excel sheet data
it gives below results for Imported Set rows Insert/Update/Ignored-
Since in the target user table, for the user 'Eric test2' record, the Manager field is NOT EMPTY, so as per the transform script condition part (targetMgr != "") it should 'Ignore' the updation of 'Eric test2' record, but as shown in above screenshot we can see yellow highlighted record of 'Eric test2' is updated which is not expected, it should be 'Ignored'.
Please note I have tested other condition (source manager contains XT or xt) and that is working fine but don't know what happen if I added targetMgr != "" condition.
Please help to modify the script so that it will work.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 01:13 AM
@Eshwar Reddy @Ashish Parab or anyone who could help here pls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 03:17 AM
Hi @rishabh31
Try below Script
var sourceMgr = source.getValue('u_manager');
var targetMgr = target.getValue('manager');
var isSourceMgrInvalid = (sourceMgr.startsWith('xt') || sourceMgr.startsWith('XT'));
var isTargetMgrNotEmpty = (targetMgr !== "");
if (isSourceMgrInvalid && isTargetMgrNotEmpty) {
ignore = true;
} else {
ignore = false;
}
Thanks
Esh