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-10-2017 07:07 AM
That's how I read it as well Chuck. But when that failed. I saw the line in the docs saying "The data source must be an existing GlideRecord object."
While I would think that just means that you must have already created the data source.. it didn't work so I tried setting data_source to a GR object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 07:44 AM
Actually.. it does not appear to be executing the pre-script at all unless I populate the datasource field.
I'll retest with that populated. It is described as an override..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 07:03 AM
Stephen, the documentation link you posted says that "The data source must be an existing GlideRecord object.". So this means that in your pre-script that you must perform a GlideRecord query and set data_source to that object.
I haven't tested it but something like the following may work:
var dataSource = new GlideRecord("sys_data_source");
dataSource.addQuery("name", "DATA SOURCE NAME");
dataSource.query();
if (dataSource.next()) {
data_source = dataSource;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 07:08 AM
Thanks Michael, but I don't believe that's materially different from what I put in my original post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2017 07:28 AM
Maybe the code expects the SysID of the datasource and not the name. try data_source = grDS.sys_id