- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 01:45 AM
There are two columns A and B in target table and when importing the data from source the values in the A and B should not repeat(should not be duplicate)
im writing below code but it is not working
var bil = source.u_xyz;
var rec =source.u_jkc;
var grAst = new GlideRecord('u_abcdef');
grAst.addQuery('xyz', bil);
grAst.addQuery(jkc', rec);
grAst.query();
if (grAst.next()){ {
errorFlag = true;
log.error(errorMessage, "File rejected due to multiple entries );
current.setAbortAction(true);
}
else{
target.xyz =bil;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 01:49 AM
Hi Avinash,
Since combination of those 2 fields is unique; why not have coalesce on those 2 fields if you are using data source, field map and transform map etc
I assume your script is in onBefore transform script; you cannot use current object there; but use ignore=true so it would ignore the entire source row
var bil = source.u_xyz;
var rec =source.u_jkc;
var grAst = new GlideRecord('u_abcdef');
grAst.addQuery('xyz', bil);
grAst.addQuery('jkc', rec);
grAst.query();
if (grAst.next()){ {
errorFlag = true;
log.error(errorMessage, "File rejected due to multiple entries );
ignore = true;
}
else{
target.xyz =bil;
target.jkc = rec; // check whether this line of code is required
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 01:49 AM
Hi Avinash,
Since combination of those 2 fields is unique; why not have coalesce on those 2 fields if you are using data source, field map and transform map etc
I assume your script is in onBefore transform script; you cannot use current object there; but use ignore=true so it would ignore the entire source row
var bil = source.u_xyz;
var rec =source.u_jkc;
var grAst = new GlideRecord('u_abcdef');
grAst.addQuery('xyz', bil);
grAst.addQuery('jkc', rec);
grAst.query();
if (grAst.next()){ {
errorFlag = true;
log.error(errorMessage, "File rejected due to multiple entries );
ignore = true;
}
else{
target.xyz =bil;
target.jkc = rec; // check whether this line of code is required
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 05:10 AM
Hi,
If the combination of A and B columns shall not repeat, then its best to create a coalesce on these 2 columns. That way, it will update existing record and not create new record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2020 10:39 PM
As stated by Asif, if you set both the fields maps as coalesce, you would not need a script.