OnAfter Script - Transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2011 07:28 AM
I have the transform Map which has Onstart, Onbefore and Onafter script.
In Onbefore script, I am checking for 2 conditions. If the conditions are met , Ignore the record.
The issue is Ignore works but the same record goes through processing in Onafter script.
I want to ignore it completely if it is matches the condition in Onbefore script.
Do I have to write the same logic as onbefore in onafter script too?
Onbefore script:
if(source.u_user_id == "" || source.u_user_id == null)
ignore=true;
else {
//bypass the user if the bypass flag is on
var checkflag = new GlideRecord('sys_user');
checkflag.addQuery('user_name',source.u_user_id);
checkflag.query();
if(checkflag.next()) {
var bypass = checkflag.u_bypass_user_profile_updates;
if(bypass) {
ignore=true;
}
}
}
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2011 07:52 AM
One could interpret this as a "bug" or a "feature" of ServiceNow. I can agree with you here that the onAfter should not fire if onBefore sets it to ignore=true. You can work around it though:
Centralize your condition into a single function using On-demand Functions and then call it from your onBefore AND your onAfter. This would allow you to have a single place to change the condition(s) around.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2015 01:27 AM
I had the same issue however my validation logic was quite time consuming so that I wanted to prevent to execute it twice. So I was somehow thinking about how to send the information about invalid record to the onAfter script and I resolved it by creating custom variable in onBefore transform script (or in Script of Transform Map record) and I set it to true if onAfter script should be ignored, otherwise to false. Then in onAfter script I checked this variable and it was available there. This was tested on Fuji release.
On Before transform script:
if (/* validation code indicates invalid values */) {
ignore = true;
var wasIgnored = true;
} else {
var wasIgnored = false;
}
On After transform script:
if (wasIgnored == false) {
// run my on after code
}