- 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-07-2021 04:06 AM
Hi Ankur,
Requirement - When data has sent through Transform map, Onbefore script should validate if same 'sys_id' was there in Target table, Then it should validate remaining fields are empty or not. If remainig fields are empty then it should delete the target record, If remaining source fields are not empty then delete the record in Target table first and then create the record again in the Target table.
Thanks & Regards,
S.Swaroop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 04:16 AM
Hi,
I have shared the above script.
Ensure you enhance it for creating record after deletion
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 04:32 AM
Hello Ankur,
Thanks for the quick response.
I am using the below script, it was deleting the record but not creating the record. Can you please suggest where i am doing it wrong.
(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()) {
target.deleteRecord();
} else {
target.insert();
}
})(source, map, log, target);
Thanks & Regards,
S.Swaroop.
- 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-07-2021 04:47 AM
Hello Ankur,
Thanks for the code.
I will use the script as mentioned and update you on the same.
Thanks & Regards,
S.Swaroop.