Conditional coalesce script creates record with sys_id of "-1"

Benjamin Nuttin
Giga Expert

I have to do a conditional coalesce on an inbound record, so I'm using a script that tries to find my target record, and if it can't, it returns -1, as explained at https://docs.servicenow.com/bundle/kingston-platform-administration/page/administer/import-sets/conc... 

For example, my field map script, which is set to coalesce, is:

answer = (function transformEntry(source) {
   var gr = new GlideRecord('incident');
   var qc = gr.addQuery('correlation_id', source.u_sys_id);
   qc.addOrCondition('sys_id', source.u_correlation_id);
   gr.query();
   if (gr.next()) {
       return gr.sys_id;
   } 
   else {
       return -1;
   }
})(source);

This works fine in most cases, but I have seen examples where this just ends up creating an incident with a sys_id of "-1". Any idea what could cause that?

 

5 REPLIES 5

SANJEEV4
Tera Contributor

@Benjamin Nuttin 

I'm also facing the same issue, Could you please provide the solution