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

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.


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..


Michael Ritchie
ServiceNow Employee
ServiceNow Employee

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;


}


Thanks Michael, but I don't believe that's materially different from what I put in my original post.


Maybe the code expects the SysID of the datasource and not the name.   try data_source = grDS.sys_id