The CreatorCon Call for Content is officially open! Get started here.

Scheduled import: How to specify the datasource dynamically?

Stephen W_
Giga Guru

According to Scheduling Data Imports - ServiceNow Wiki

I should be able to override the datasource in a scheduled data import using the "Pre script".

However, it does not use either:

data_source = "My DS Name";

or

var grDS = new GlideRecord("sys_data_source");

if (grDS.get("name","My DS Name")){

  data_source = grDS;

}

if I leave the basic datasource field blank:

Unresolved data source for ScheduledImportJob


If I populate it, it hits the wrong datasource.

Is this a bug, bad documentation.. or am I just missing something?

Thanks,

-Stephen

Fuji patch12 hotfix1

14 REPLIES 14

oharel
Kilo Sage

Try this:


var grDS = new GlideRecord("<Data source data_source_table_name>");



For example, I have


var grDS = new GlideRecord("<Data source u_dt_ldap_sites>");



harel


That doesn't make sense to me.   I've never seen GR instantiated that way.


I've been wrong many times before, so I went ahead and tried your suggestion every-which-way, but it's no better:



If my import table is named "import_table" and my data source is named "MyDataSource":


You're saying I would use this?


        var grDS = new GlideRecord("<MyDataSource import_table>");  



Tried with and without the gt/lt


        var grDS = new GlideRecord("MyDataSource import_table");  



I assumed "Data source" is actually supposed to be the name of your data source.. but in-case I was wrong I tried it


        var grDS = new GlideRecord("<Data source import_table>");


        var grDS = new GlideRecord("Data source import_table");



Or


        var grDS = new GlideRecord("<import_table>");


        var grDS = new GlideRecord("import_table");



Since your instructions wouldn't be a glide record of the data source table ("sys_data_source") I wouldn't be able to 'get' the DS record, but I tried it both ways for each scenario above anyway.


      var grDS = new GlideRecord(....


        data_source = grDS;


          //vs.


        var grDS = new GlideRecord(....


        if (grDS.get("name","My DS Name")){


                  data_source = grDS;


        }


I've tried every variation on that that I could.. nothing working any differently. "Unresolved data source for ScheduledImportJob".


Can you explain what the strange syntax actually does(And clarify how to use it) and what was wrong with my old code?



The only solution I can see is to use multiple schedule items for the same time-slot with exclusive launch conditions.


This is frustrating though, since, while not clear, the documentation does state this should be possible..


The way I read it, Stephen, is that the line simply goes in the Pre script



data_source = "My Data Source";



where "My Data Source" is a record defined in System Import Sets> Administration> Data Sources.