Scheduled import: How to specify the datasource dynamically?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 10:34 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 10:44 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 11:01 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 02:10 PM
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..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 07:01 AM
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.