Problem using Data Lookup Matchers in the context of an import/transform

thomaskennedy
Tera Guru

I’m using Data Lookup Matcher Rules to populate some Reference columns in my Import Set based on vendor key values in the source file. For example, vendor part id 12345 might get mapped to cmdb_model record “Routers”. The reference is what I want pushed into the target table.

 

The matcher rules work as expected when I open an Import Set row and populate the Part ID field.

 

However, I need these rules to run in the context of an import, right before my Transform Map runs. And I find that they are not running – at least, not by the time the transform runs.

 

My Data Source is polled by a Scheduled Data Import. The import reads data from my Data Source and populates an import set. Because my Data Source has a Transform Map associated with it, the transform runs immmediately. And here is where things go wrong. The transformRow event checks that those References have been populated, so as to filter out rows where these are empty. I find they have not been populated, and it skips inserting that row to the target.

 

if(!source.getValue("u_model")) {

    ignore = true;

    return;

}

 

But if I open the Import Set, the references are populated.

 

thomaskennedy_0-1695857448994.png

 

I think this is a race condition. It seems as if the matcher rules are running asynch (that is, upon an insert/update to my import set table), and the transform is not allowing time for this process to run. But the transform runs immediately, because it’s tied to my data source. Is my theory correct?

 

Assuming yes, the question is how can I restructure this to separate the creation of my import set from the running of the transform, and allow enough time between those two for the matcher rules to run?

 

All I can think of is to create my import set through a script and then schedule a run of GlideImportSetTransformer a few minutes later. Is there a better option or one with less scripting?

 

 

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Nice research on your end and I would agree, it sounds like a timing issue. Off the top of my head, you could switch everything to script, but there's a potential to maybe add a sleep to the onStart of that transform map to give the system a moment or two to get those values populated. I've never tried it and normally don't encourage the use of it, but you could try a gs.sleep(milliseconds here) -- alternatively, you could inject async processing of that transform (using condition of the target table, for example) -- and then call GlideImportSetTransformer as you've mentioned, here's a support article with a script for a business rule that could help you get started: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0781666 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

Nice research on your end and I would agree, it sounds like a timing issue. Off the top of my head, you could switch everything to script, but there's a potential to maybe add a sleep to the onStart of that transform map to give the system a moment or two to get those values populated. I've never tried it and normally don't encourage the use of it, but you could try a gs.sleep(milliseconds here) -- alternatively, you could inject async processing of that transform (using condition of the target table, for example) -- and then call GlideImportSetTransformer as you've mentioned, here's a support article with a script for a business rule that could help you get started: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0781666 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

OK, so I'm not crazy or missing anything big. I will break this up, and create my import set through script. I'll have that script populate the References using Decision tables & the related API up front (I'll drop the Data Matchers). That sounds expensive, but it will be lightweight if I first iterate through all the DT keys/values and load these into a map.  If a part id doesn't map to anything I skip that row. Then I'll just schedule the transform. There will be little or nothing for transformRow to do because the empties/don't want rows have been skipped up front.

No, you're not crazy or missing anything big, haha.

 

Sounds good, if you need help with any particular piece, let us know?

 

If my reply above helped confirm and guide you, please take a moment to consider marking it as Helpful/Accept Solution.

 

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!