Transform Map in Synchronous Mode - Coalesce Field Script Called Twice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 09:16 AM
I have noticed a strange behaviour in executing Transform Maps in synchronous mode (i.e. via background script or web service).
Normally (in asynchronous mode), transform scripts are executed in this order:
- onStart
- field source script for coalesce fields
- onBefore
- other source scripts
- transform script
- ...
However, with synchronous mode, field source scripts for coalesce fields is called twice:
- field source script for coalesce fields (extra call)
- onStart
- field source script for coalesce fields
- onBefore
- other source scripts
- transform script
- ...
Of course, if your coalesce field source script relies on anything declared in an onStart script, you are out of luck.
Is it a bug or a feature?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 09:20 AM
Hi Martin,
Ideally this should not happen
Did you try adding log statements to granular level?
var gdt = new GlideDateTime();
gs.info(gdt.getNumericValue());
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
‎09-04-2019 09:31 AM
Hi Ankur,
thanks for your hint.
I've put log statements to my transform map scripts (onStart, onBefore, a scripted source field with coalesce=true and with coalesce=false). Then I inserted a test record to my import table in an background script, which triggered the transform map synchronously.
Therefore I see the order of log statements (gs.log) directly in the script output in the order they were executed in.
I observed the problem on a client's instance and was able to reproduce it on my development instance.
It looks like a bug to me.
Kind regards,
Martin
The background script:
var gr = new GlideRecord("imp_user");
gr.initialize();
gr.email = "blablabla@blablabla.bla";
gr.first_name = "First";
gr.last_name="Last";
gr.insert();
*** Script: 10
Martin: Mapping coalesce
Martin: onStart
Martin: Mapping coalesce
Martin: onBefore
Martin: Mapping remaining
Slow business rule 'Transform synchronously' on imp_user:11, time was: 0:00:00.128
A coalesce field script:
onStart script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 09:35 AM
Just a note:
I had a function called mapAssetId(...) {
return ...
}
in an onStart script, which a coalesce source script was supposed to use. It worked in asynchronous mode.
But in synchronous mode, I was getting an error. This is how I realised there was something wrong.
Evaluator: org.mozilla.javascript.EcmaError: "mapAssetId" is not defined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 09:53 AM
Hi Martin,
you won't see the actual logs unless you add numeric value i.e. seconds
add something similar to this
gs.log('Transform MAP onStart value is ' + new GlideDateTime().gdt.getNumericValue());
also mapAssetId is not defined means you have not declared some variable but using it; also there must not be any value into it
can you share the script here?
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