Script Action is not working

Pratiksha Lang1
Kilo Sage

I have an event triggered from UI action followed by script action, but the script action code is not working. 

event and script action both is getting triggered but the script action code is not working. Please find the code below:

 

Script Action:

 

var sourceSite = event.parm1;
var destinationSite = event.parm2;
 
importAll(sourceSite,destinationSite);
 
function importAll(sourceSite,destinationSite){
 
var targetTable = new GlideRecord('x_amspi_smdrs_app_olas');
targetTable.addQuery('site',current.source_site);
targetTable.query();
while (targetTable.next()) {
gs.info('Inside the script action second');
    var targetTable1 = new GlideRecord('x_amspi_smdrs_app_olas');
    targetTable1.addQuery('ola_name', targetTable.ola_name);
    targetTable1.addQuery('frequency_ola', targetTable.frequency_ola);
    targetTable1.addQuery('function_ola', targetTable.function_ola);
    targetTable1.addQuery('sub_function_ola', targetTable.sub_function_ola);
    targetTable1.addQuery('formula_ola', targetTable.formula_ola);
    targetTable1.addQuery('ola_type', targetTable.ola_type);
    // targetTable1.addQuery('status', targetTable.status);
    targetTable1.addQuery('role', targetTable.role);
    // targetTable1.addQuery('artefacts', targetTable.artefacts);
    targetTable1.addQuery('site',current.destination_site);
    targetTable1.query();
 
    if (targetTable1.next()) {
gs.info('Inside the script action third');
        gs.addErrorMessage('Record already exists in ola table: ' + targetTable1.ola_name);
 
    } else {
gs.info('Inside the script action fourth');
         targetTable1.initialize();
         targetTable1.ola_name = targetTable.ola_name;
         targetTable1.frequency_ola = targetTable.frequency_ola;
         targetTable1.function_ola = targetTable.function_ola;
         targetTable1.sub_function_ola = targetTable.sub_function_ola;
         targetTable1.formula_ola = targetTable.formula_ola;
         targetTable1.ola_type = targetTable.ola_type;
         targetTable1.status = targetTable.status;
         targetTable1.role = targetTable.role;
         targetTable1.artefacts = targetTable.artefacts;
         targetTable1.site = current.destination_site;
         targetTable1.insert();
         gs.addInfoMessage('Record Inserted Successfully');
    }
}
}
 
 
 
UI Action :
 
var source = current.getValue('source_site');
var destination = current.getValue('destination_site');
gs.eventQueue("x_amspi_smdrs_app.smdrs.import", null, source, destination);
11 REPLIES 11

Can you also print what are you getting in 'sourceSite ' and 'destinationSite ' from parm1 and parm2?

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Aman Kumar S
Kilo Patron

Hi @Pratiksha Lang1 ,

For eventqueue function, why are you passing the 2nd parameter as "null".

You will need to pass the object for the table for which you have created the event.

Best Regards
Aman Kumar

Pratiksha Lang1
Kilo Sage

@Aman Kumar S If I give current then it is not triggering the script action, so I have given null. As current will run only till the event is triggered and after that it gets deleted

Are you sure about this, you can refer to OOB metric "Metric Update" for better understanding.

Best Regards
Aman Kumar