Ignore Records in a transform Map

ursnani
Giga Guru

Hi,

I am trying to load data and run a transform map to load them to target table. My requirement is if I try loading the data which I am not expecting then it should just ignore the record and update the remaining records.

 

Sample Data is as below.

find_real_file.png

 

I am trying to run a onBefore Script and checking for the Number which will always start with certain prefix like INC or SINC and ignore SrINC records. Below is the code which I am using when I run the transform map.

var str = source.u_number;
    var incregex = /^INC/;
	var sniregex = /^SINC/;
	
	
	if(!incregex.test(str) || !sniregex.test(str)){
		
		ignore = true;
	}

 

Any help on this is very much appriciated.

 

Thank you in Advance

1 ACCEPTED SOLUTION

Try this

It should work - onBefore transform map script

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

	var str = source.u_number;		
	str = str.replace(/[0-9]/g, ''); //replace all numeric part
	if((str == 'INC' || str == 'SINC') && (action == 'insert' || action == 'update'))
        {		
		}
	else
		{
		ignore=true;
		}

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

Let me know then if you need any further help

Regards,
Anshu

View solution in original post

7 REPLIES 7

Thanks Anshu that helped

Muhammad Khan
Mega Sage
Mega Sage

Hi ursnani,

 

You can use the following script;

var str = source.u_number.toString();
if(str.search(/INC[0-9]/i) != 0 && str.search(/SINC[0-9]/i) != 0)
    ignore = true;

 

Hopefully this will resolve your query.

VaranAwesomenow
Mega Sage

Since ServiceNow recommends to start using robust transform map where possible vs transform map, in order to implement ignore functionality

You can implement this in 3 ways
1. Implement on before script on ETL
    gliderecordusing key field from source / target -> if found
        //status = 'SKIPPED';
        or
        //ignore = true;
2. Implement on after script on ETL
    On after can access target Object, so you can run a set query to check if its a valid record or not and do a delete.
3. Write a post import script on scheduled import that will do the delete