Ui action popup is dissapeared and server side code is not exceuting.

Kishor O
Tera Sage

I have created a UI action that has both client and server-side code but the server script is not executing and ui page is disappearing in a second.

 

Here is code for ui action

function importQC() {


    // var answer = confirm('Please attach excel sheet to create bulk task');

    // if (answer == true) {
    var gdw = new GlideDialogWindow('attachment_custom');

    gdw.setSize(750, 300);



    gdw.setPreference('target_sys_id', g_form.getUniqueValue());


    gdw.setPreference('target_table', g_form.getTableName());


    gdw.setPreference('attachment_disabled', false);


    gdw.render();

    gsftSubmit(null, g_form.getFormElement(), "fj_import_qc");

}


if (typeof window == 'undefined')
    serverReopen();

function serverReopen() {
    gs.log('kissh');
    var gr2 = new GlideRecord("sys_attachment");
    gr2.addQuery("table_sys_id", current.sys_id);
    gr2.addQuery("table_name", "sc_req_item");
    gr2.query();
    if (gr2.next()) {
        gs.log('ajj');
        // gs.addErrorMessage("You must attach a file to submit. Your import submission has been aborted.");
        // current.setAbortAction(true);



        GlideSysAttachment.copy(current.getTableName(), current.sys_id, 'sys_data_source', 'b5aad514473002101a5c7f52d16d43eb');

        var ms = 5000; // 5 seconds

        var endSleep = new GlideDuration().getNumericValue() + ms;
        while (new GlideDuration().getNumericValue() < endSleep) {
            //wait
        }

        var exportGr = new GlideRecord("scheduled_import_set");
        exportGr.addQuery("sys_id", "38f402f447fc02101a5c7f52d16d4318"); // sys_id of the record which you will be creating for scheduled import in step
        exportGr.query();
        if (exportGr.next()) {
            //gs.executeNow(exportGr); // this is for scoped app
            SncTriggerSynchronizer.executeNow(exportGr); // this is for non scoped app
        }
    }
    action.setRedirectURL(current);
}

KishorO_0-1709709499445.png

 

 

2 REPLIES 2

GopalBarde
Tera Contributor

When I Go through your script there are some changes that has to be made to run the script but still on click of that button there 's nothing happend.

here is  my script  might be work on your instance though please check it.

button is appearing but on click of that button its not working for my instance check your instance if its work or not

here is the script for that 

 

function importQC() {
    var gdw = new GlideDialogWindow('attachment_custom');
    gdw.setSize(750, 300);
    gdw.setPreference('target_sys_id', g_form.getUniqueValue());
    gdw.setPreference('target_table', g_form.getTableName());
    gdw.setPreference('attachment_disabled', false);
    gdw.render();
    gsftSubmit(null, g_form.getFormElement(), "fj_import_qc");
}

if (typeof window === 'undefined') {
    serverReopen();
}

function serverReopen() {
    gs.log('kissh');

    var gr2 = new GlideRecord("sys_attachment");
    gr2.addQuery("table_sys_id", current.sys_id);
    gr2.addQuery("table_name", "sc_req_item");
    gr2.query();

    if (gr2.next()) {
        GlideSysAttachment.copy(current.getTableName(), current.sys_id, 'sys_data_source', 'b5aad514473002101a5c7f52d16d43eb');

        // Adding a delay using GlideDuration (sleep) - Not recommended in a real-world scenario
        var ms = 5000; // 5 seconds
        var endSleep = new GlideDateTime();
        endSleep.addMilliseconds(ms);
        while (new GlideDateTime().compareTo(endSleep) < 0) {
            // Wait
        }

        // Execute a scheduled import set
        var exportGr = new GlideRecord("scheduled_import_set");
        exportGr.addQuery("sys_id", "38f402f447fc02101a5c7f52d16d4318"); // Update with the correct sys_id
        exportGr.query();

        if (exportGr.next()) {
            // Execute the scheduled import set
            // gs.executeNow(exportGr); // For scoped app
            SncTriggerSynchronizer.executeNow(exportGr); // For non-scoped app
        }
    }

    action.setRedirectURL(current);
}

  

@GopalBarde Can you tell what changes you have made for the above script? It looks same