- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2021 09:51 AM
Hello All,
When a record is passed using Transform Map, and if sys_id of the source record matches with Target record and if it contains all the fields empty then it should delete the target record. Can anyone suggest me how to do that.
Thanks & Regards,
S.Swaroop.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 04:40 AM
Hi,
As I said you have to enhance my script
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var gr = new GlideRecord('incident');
gr.addQuery('number', source.u_number);
gr.query();
if (gr.next()) {
gr.deleteRecord();
gr.initialize();
gr.number = source.u_number;
gr.short_description = 'My Testing';
gr.insert();
} else {
ignore = true; // since record not found
}
})(source, map, log, target);
Regards
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-06-2021 11:32 AM
Hi Swaroop,
You have the scenario if the record is already present with the same sys_id then it should delete the record.
you can achieve by writing in the onBefore transform script , it will validate before inserting the record in the target table .
Please mark correct if its helpful.
Regards,
Amit Gujarathi
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 03:16 AM
Hello Amigujarathi,
Excatly, i stuck with the script. Can you help me with the Onbefore Script for validation and deletion of the record.
Thanks & Regards,
S.Swaroop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 03:42 AM
update as this in onBefore transform script
I have taken an example of incident table and Coalesce on number field
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var incNumber = source.u_number;
var gr = new GlideRecord('incident');
gr.addQuery('number', incNumber);
gr.query();
if(gr.next()){
// check here for all target fields are empty or not
// if yes then delete the record using gr.deleteRecord()
ignore = true;
}
else{
ignore = true;
}
})(source, map, log, target);
Regards
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-07-2021 03:42 AM
Hi,
I just shared the script.
But would like to understand the business use-case/requirement around this
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader