Transform Script help - onBefore

matt_a
Kilo Guru

Hello,

I wanted to create a transform map script that checked the target to see whether a boolean field was set to true. If set to true, then to ignore. If set to false, to carry on and update the record.

I created an onBefore script with the following:

	var dup = new GlideRecord('sys_user');
	dup.addQuery('u_duplicate_record', true);
	dup.query();
	if (dup.next()) {
		ignore = true;
	}

However, its ignoring all records! Can someone point out what I have done wrong please?

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onBefore transform script since you already know the target record

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

	// Add your code here
	if(target.u_duplicate_record.toString() == 'true')
		ignore = true;

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Jorn van Beek
Tera Guru

if you have a single record in the sys_user table with the u_duplicate_record is true it will ignore all records.

With every record you you check if there is a sys_user record that has duplicate = true then you ignore. I think you want to query if the target record has duplicate = true then ignore.

I would change the script from on before to run during transform (the one on the transform form itself).

change the script to:

ignore = target.u_duplicate_record;

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onBefore transform script since you already know the target record

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

	// Add your code here
	if(target.u_duplicate_record.toString() == 'true')
		ignore = true;

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

That seems to have worked well. Thank you so much for your help @Ankur Bawiskar