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

Execute pre-import script - Data stream

sunilsargam
Tera Guru

I need to pass a single input parameter to a Data Stream using the Pre-Import Script.

I've already defined this input parameter in the Data Stream configuration.

I've also set up a Scheduled Import and linked it to a Data Source.

In the Data Source, I selected the type as Data Stream, and below that, I can see the input parameter fields where I can provide values dynamically.

5 REPLIES 5

nityabans27
Kilo Sage

Hi @sunilsargam ,

Use the Pre-Import Script in your Data Source to set Data Stream parameters dynamically before import runs.

Example:

(function(import_set_run, data_source) {
    var yesterday = new GlideDate();
    yesterday.addDaysUTC(-1);
    data_source.setParameterValue('u_start_date', yesterday.getDisplayValue());
})(import_set_run, data_source);

✅ This overrides any static value in the Data Source form.
✅ Ideal for passing dynamic inputs like dates, sys_ids, or last import timestamps.

sunilsargam
Tera Guru

Thank you @nityabans27 , 

 

 I have added below script in scheduled import pre script section. this is not passing value to data stream. i have added logs to see if this is getting executed. no logs captured. 

 

(function(import_set_run, data_source) {
    var hoursAgo = 1;
    var past = new GlideDateTime();
    past.addSeconds(-hoursAgo * 60 * 60);
    var isoDate = past.getValue();

    var query = "$top=1000" + "&$select=ID" + "&$orderby=Id desc" + "&$filter=Modified ge '" + isoDate + "'";

    var yesterday = new GlideDate();
    yesterday.addDaysUTC(-1);
    data_source.setParameterValue('query', query);
    gs.info("log quiery predata" + query);
})(import_set_run, data_source);

Use Scheduled Data Import’s "Pre-Execution Script"

Go to your Scheduled Import record → scroll to the Pre-Execution Script field → place your code there:

(function(import_set_run, data_source) { var hoursAgo = 1; var past = new GlideDateTime(); past.addSeconds(-hoursAgo * 60 * 60); var isoDate = past.getValue(); var query = "$top=1000&$select=ID&$orderby=Id desc&$filter=Modified ge '" + isoDate + "'"; data_source.setParameterValue('query', query); gs.info("Scheduled Import Pre-Execution Script - Query: " + query); })(import_set_run, data_source);

This script does execute before a Data Stream call during scheduled imports.

yes. i have done the same. 

 

sunilsargam_0-1760601926523.png