Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Performance of scripted vs. regular field mapping for reference fields in transform maps

Max Nowak
Kilo Sage

Hi,

I'm curious about the overhead of using a scripted field mapping for a reference field in a transfor map. Just thinking about it, I feel like a scripted field mapping might have better performance if the table I'm referencing is relatively large, and I'm able to reduce the number of records to search through a gliderecord query.

 

For example, just for fun, imagine I'd be importing into a table that references the CMDB, and for whatever reason, the field is not referencing a specific CMDB table, but just cmdb_ci. Now, that table could be very large, possibly millions of records.

 

Now, let's say I know that the records I want to import only ever reference a specific CI Class, AD Controllers ("cmdb_ci_ad_controller"). While I have a few AD Controllers, it's certainly much, MUCH less than the millions of records in the whole CMDB.

 

In that case, if I'd use a scripted field mapping like this:

 

answer = (function transformEntry(source) {
  var adcGr = new GlideRecord('cmdb_ci_ad_controller'); // Narrowing the search down to only AD Controllers
  var found = adcGr.get('name', source.u_name); // Assume that I can safely identify records by name

  if(found) {
    return adcGr.getUniqueValue();
  }
})(source);

 

 

Would that increase the performance, since I narrowed the search space down from millions of records to less than 100, or is the overhead from using a scripted field mapping so great that it doesn't matter?

 

Thanks for your help,

Max

1 REPLY 1

Mark Manders
Mega Patron

In this case always use a script. You are getting a string and need to find the reference. The chance that there is more than one CI with the same name, is theoretically not small. So you want the correct table. I have never tested the difference in performance, but the chances of getting the wrong CI would be too large to not use a script.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark