Transform Map in Synchronous Mode - Coalesce Field Script Called Twice

Martin76
Kilo Expert

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:

  1. onStart
  2. field source script for coalesce fields
  3. onBefore
  4. other source scripts
  5. transform script
  6. ...

However, with synchronous mode, field source scripts for coalesce fields is called twice:

  1. field source script for coalesce fields (extra call)
  2. onStart
  3. field source script for coalesce fields
  4. onBefore
  5. other source scripts
  6. transform script
  7. ...

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?

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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:
find_real_file.png
onStart script:
find_real_file.png

 

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.


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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader