How to run Scheduled Data Import at random times of the day

Ereshkigal
Tera Contributor

Hi.

I want to import Data Source once a day.

Also, the time when importing once a day should be random.

I understand that I use Scheduled Data Import, but I don't know how to do it.

Help me!

Thank you!

 

3 REPLIES 3

Anshu_Anand_
Kilo Sage
Kilo Sage

when you use scheduled import set and set any time or condition,

That will run the data source which will run the transform map connected to it.

Random timing is tricky part . you can use periodically every midnight or time when transactions are less or off business hours

find_real_file.png

Please mark my answer as correct if its helpful

 

Regards,
Anshu

Maik Skoddow
Tera Patron
Tera Patron

Hi

in "Scheduled Import" records you have a checkbox field "Execute post-import script". After checking this you will be offered with a script field. In that field get the record of the same Scheduled Import and set a random time for the next schedule.

At the end the Scheduled Import modifies itself.

Kind regards
Maik

Hitoshi Ozawa
Giga Sage
Giga Sage

I'll just create a scheduled job to run at midnight to reset the time to run the scheduled data import.

Sample code:

var schDataImportSysId = '<sys_id of scheduled data import>';  // sys_id of scheduled data import to execute

var grSchDataImport = new GlideRecord('scheduled_data_import');
if (grSchDataImport.get(schDataImportSysId )) {
  var gt = new GlideTime();
  var hour = Math.floor(Math.random() * 24);    // random hour
  var minute = Math.floor(Math.random() * 60);  // random minute
  var second = Math.floor(Math.random() * 60);  // random second
  hour = ('00' + hour).slice(-2);
  minute = ('00' + minute).slice(-2);
  second = ('00' + second).slice(-2);

  gt.setValue(hour + ':' + minute + ':' + second);  // reset execution time
  grSchDataImport.setValue('run_time', gt);
  grSchDataImport.update();
}