Scheduled job script for notification trigger when data got lodded

pushpaalath
Tera Contributor

I have created a notification and event on (sys_import_set_run) table. for calling in schedule job script
Notification : SFX Data load (Pic1)
Event : sfx_dataload (pic2)
here I need to call the notification & event in my schedule job script. But existing I already have some script can you please help me with the scheduled job script (pic3)
schedule job existing script :

var gr = new GlideRecord('sys_data_source');
var dataID = gs.getProperty('swimlane1.sfx.material.id.data.source');
if(gr.get(dataID)){

var gdt = new GlideDateTime().getLocalDate().getByFormat("yyyy-MM-dd").toString();
var arrD = gdt.split('-');
var fileDate = arrD[0]+arrD[1]+arrD[2];
var path = gr.file_path;
var x = path.indexOf('CustMat');
var newPath = path.substring(0,x);
newPath = newPath +'CustMat_'+fileDate+'.csv';
gs.log('SL1 material ID SFX path : ' + newPath,'SFX_LOAD');
gr.file_path =path+newPath;
gr.update();
gs.log("****LOK file updated",'SFX_LOAD');
}

gs.log('****LOK schedule started','SFX_LOAD');

 

pushpaalath_0-1714810115898.png

 

Thanks

1 REPLY 1

Amitoj Wadhera
Kilo Sage

Hi @pushpaalath ,

 

Modify your scheduled job script to include the logic to queue the sfx_dataload event for a record in the sys_import_set_run table.

Here's an example of how you can modify your script:

 

// Existing script
var gr = new GlideRecord('sys_data_source');
var dataID = gs.getProperty('swimlane1.sfx.material.id.data.source');
if (gr.get(dataID)) {
    // Get the local date in the format yyyy-MM-dd
    var gdt = new GlideDateTime().getLocalDate().getByFormat("yyyy-MM-dd").toString();
    var arrD = gdt.split('-');
    var fileDate = arrD[0] + arrD[1] + arrD[2];
    
    // Adjust the file path
    var path = gr.file_path;
    var x = path.indexOf('CustMat');
    var newPath = path.substring(0, x);
    newPath = newPath + 'CustMat_' + fileDate + '.csv';
    
    // Update the file path and log it
    gs.log('SL1 material ID SFX path: ' + newPath, 'SFX_LOAD');
    gr.file_path = newPath;
    gr.update();
    gs.log("****LOK file updated", 'SFX_LOAD');
}

gs.log('****LOK schedule started', 'SFX_LOAD');

// New part of the script to queue the event
// Replace 'sys_import_set_run' with the appropriate table name for your use case

var importSetRunGR = new GlideRecord('sys_import_set_run');
importSetRunGR.query();
while (importSetRunGR.next()) {
    // Queue the event for each record in sys_import_set_run
    gs.eventQueue('sfx_dataload', importSetRunGR, importSetRunGR.sys_id, '');
}

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj