Transform: On Before script not working

David A2
Giga Guru

I have a transform map setup with a primary map script and an onBefore script. I can't seem to get the onBefore script to function. Either Does anyone have any suggestions why it might not be working? In general I do not want the transform to create any new CI's and I only want CI's updated where the u_vendor_job_id on the target record is empty. The Vendor Job ID field is just a standard string field. Nothing unique.

 

Primary map script

if (action == 'insert') {
	ignore == true;
}

onBefore script

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

if(target.u_vendor_job_id != '') 
   ignore = true; 

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

 

1 ACCEPTED SOLUTION

thomaskennedy
Tera Guru

Here's what I got to work. Given a source file like this:

 

NameRankSerialNumber
Billy BobMajorDomoH3422B
NestorLackeyR344-9
XerxesEmperor35563
LebowskiDude11111

 

And a target table with only the first three rows:

 

thomaskennedy_0-1693431373634.png

I set up my onBefore script like this. Note that my script, and not a Field Map, is deciding what the coalesce column is.

 

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

// No inserts
var gr = new GlideRecord("x_acso_test_app_target_row");
gr.addQuery("u_serial_number", source.u_serialnumber);
gr.query();
if(!gr.next()) {
ignore = true;
return;
}

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

 

When I run the transform, the target table is unchanged.

 

To prevent updates unless the target Rank column is empty, I updated the onBefore:

 

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

   ...
	
	// No update unless target rank is empty
	if(target.u_rank != '') {
		ignore = true;
		return;
	}

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

 

Now if I update my source file with a new value but leave the target table alone, no update is done.

thomaskennedy_1-1693431775580.png

thomaskennedy_2-1693431918013.png

But if I clear out the target column and run the transform again, the update is applied.

thomaskennedy_3-1693431999521.png

thomaskennedy_4-1693432116748.png

It seems to me you should not have to resort to using GlideRecord like this, but this is the only thing I found that worked.

 

 

 

 

View solution in original post

3 REPLIES 3

jonsan09
Giga Sage
Giga Sage

Looks like your onbefore script if statement is missing curly brackets, try the below

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

if(target.u_vendor_job_id != '') {
   ignore = true; 
}

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

In JavaScript, if the brackets are omitted the remainder of the line is considered the body, or the following line if there is no remainder.

thomaskennedy
Tera Guru

Here's what I got to work. Given a source file like this:

 

NameRankSerialNumber
Billy BobMajorDomoH3422B
NestorLackeyR344-9
XerxesEmperor35563
LebowskiDude11111

 

And a target table with only the first three rows:

 

thomaskennedy_0-1693431373634.png

I set up my onBefore script like this. Note that my script, and not a Field Map, is deciding what the coalesce column is.

 

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

// No inserts
var gr = new GlideRecord("x_acso_test_app_target_row");
gr.addQuery("u_serial_number", source.u_serialnumber);
gr.query();
if(!gr.next()) {
ignore = true;
return;
}

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

 

When I run the transform, the target table is unchanged.

 

To prevent updates unless the target Rank column is empty, I updated the onBefore:

 

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

   ...
	
	// No update unless target rank is empty
	if(target.u_rank != '') {
		ignore = true;
		return;
	}

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

 

Now if I update my source file with a new value but leave the target table alone, no update is done.

thomaskennedy_1-1693431775580.png

thomaskennedy_2-1693431918013.png

But if I clear out the target column and run the transform again, the update is applied.

thomaskennedy_3-1693431999521.png

thomaskennedy_4-1693432116748.png

It seems to me you should not have to resort to using GlideRecord like this, but this is the only thing I found that worked.