The CreatorCon Call for Content is officially open! Get started here.

OnBefore Transform Script - DONOT Insert/update records on condition

rishabh31
Mega Sage

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

rishabh31_0-1729064933180.png

it gives below results for Imported Set rows Insert/Update/Ignored-

rishabh31_2-1729065043652.png

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

 

2 REPLIES 2

rishabh31
Mega Sage

@Eshwar Reddy @Ashish Parab or anyone who could help here pls

 

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