Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Transform map Scripts

Vignesh21
Kilo Guru

Hi,

Can someone let me know why its importing record from excel.

Requirement: Ignore a record to be inserted if u_name field on source records is empty.

I have created onBefore scripts as below

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

	
	if(source.u_name == '' && action == 'insert'){
	
	ignore = true;
	
}
})(source, map, log, target);

 

also i have onComplete script

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

	var gr = new GlideRecord ('cmdb_ci_ec2_instance');
	gr.addQuery('state','!=','terminated'); 
	gr.query();
	while(gr.next()){
			
		
		var src = new GlideRecord('ec2__load');
		src.addQuery('u_instance_id',gr.object_id);
		src.addQuery('sys_import_set.number',import_set.number);
		src.query();
		if(!src.next()){
			
 			gr.state = 'terminated';
 			gr.update();
		}
	
	}
	
	var gr1 = new GlideRecord ('cmdb_ci_ec2_instance');
	gr1.addNullQuery('u_i_project'); 
	gr1.addQuery('state','!=','terminated');
	gr1.addQuery('state','!=','terminating');
	gr1.query();
	while(gr1.next()){
		gr1.state = 'error';
		gr1.update();
	}
	})(source, map, log, target);

Another script is onAfter :

if(source.u_cost_center == ""  ){
		target.state = 'error';
		target.cost_center = "";
		target.update();
	}

Once I load the data without u_name it's not inserting records, but if any other column u_i_project & u_cost_center has empty value then its inserting a recordsbut empty value as shown below. 

find_real_file.png

 

Can someone help me why i am getting these records inserted?

 

Thanks,

Vignesh

10 REPLIES 10

Even after changing its not working Vkacineni