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

Add delay to my ui action

MaharshiC
Tera Contributor

Hi,

 

I have an ui action which creates a new task. Now once its clicked it takes a few seconds for the task to get created. Now if the user clicks multiple times on the ui action at the same time then it creates multiple tasks. So i need to deactivate my ui action or add a delay of maybe 10 sec before it can again be clicked. How can this be achieved?

18 REPLIES 18

function onClick(g_form) {
    var errorMsg = false;
    var validatorFieldsFromTaskTable = ["no_of_tags_reviewed"];

    for (var i in validatorFieldsFromTaskTable) {
        g_form.setMandatory(validatorFieldsFromTaskTable[i], true);
        if (g_form.getValue(validatorFieldsFromTaskTable[i]) == "") {
            errorMsg = true;
        }
    }
    if (errorMsg == true) {
        var errorMessage = "Fill the Mandatory Fields : Review Items. Please fill and save then click on Request endorsement";
        g_form.addErrorMessage(errorMessage);
    }
    //g_form.addInfoMessage("Dev is in progress");
    if (errorMsg == false) {
        var requestEndorsementObj = {
            task_sys_ID: g_form.getUniqueValue(),
            action: "Request Endorsement"
        };
        var ga = new GlideAjax("x_iem_tqa.tqaTaskCreationUtils");
        ga.addParam("sysparm_name", "validateAction");
        ga.addParam("sysparm_requestEndorsementObj", JSON.stringify(requestEndorsementObj));
        ga.getXMLAnswer(function(answer) {
            if (answer) {
                g_form.addInfoMessage(answer);
            }
            setTimeout(function() {
                g_form.reload();
            }, 10000);
        });
    }
}

HI @Chaitanya ILCR ,

 

This is the UI action script and in the script include i am creating the task. I am hiding the UI action once the task is created but the issue is coming when they are clicking multiple times on the button at the same time

Hi @MaharshiC ,

function onClick() {
    var errorMsg = false;
    var validatorFieldsFromTaskTable = ["no_of_tags_reviewed"];

    for (var i in validatorFieldsFromTaskTable) {
        g_form.setMandatory(validatorFieldsFromTaskTable[i], true);
        if (g_form.getValue(validatorFieldsFromTaskTable[i]) == "") {
            errorMsg = true;
        }
    }
    if (errorMsg == true) {
        var errorMessage = "Fill the Mandatory Fields : Review Items. Please fill and save then click on Request endorsement";
        g_form.addErrorMessage(errorMessage);
    }
    //g_form.addInfoMessage("Dev is in progress");
    if (errorMsg == false) {
        // var requestEndorsementObj = {
        //     task_sys_ID: g_form.getUniqueValue(),
        //     action: "Request Endorsement"
        // };
        // var ga = new GlideAjax("x_iem_tqa.tqaTaskCreationUtils");
        // ga.addParam("sysparm_name", "validateAction");
        // ga.addParam("sysparm_requestEndorsementObj", JSON.stringify(requestEndorsementObj));
        // ga.getXMLAnswer(function(answer) {
        //     if (answer) {
        //         g_form.addInfoMessage(answer);
        //     }
        //     setTimeout(function() {
        //         g_form.reload();
        //     }, 10000);
        // });
        gsftSubmit(null, g_form.getFormElement(), 'create_task_endorsement' /*action name value here*/ );

    }

}


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

function serverLogic() {
    //write your server side logic here whatever you have written in the method validateAction in the script include x_iem_tqa.tqaTaskCreationUtils
    //here in this function you will have access to "current" object and server side functionality

    current.update();
    // gs.addInfoMessage('server run'); //messge if any
    action.setRedirectURL(current);
}

ChaitanyaILCR_0-1747735841664.png

 

you can combine the server code and client code in the same ui action 

 

give some value to the Action name field in the UI action( you will use this name in the UI action code give a Unique name something that's different from the existing UI action names or you can go with what I have shared)

 

comment the Glide Ajax code and write the server code inside the serverLogic function in the code I have shared 

you can use current object and server side code inside the serverLogic function 

keep the current.update and the other lines add your code above the current.update()

 

 

if you have any issues implementing this please share the code script include 

x_iem_tqa.tqaTaskCreationUtils

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

 

shantanu_patel8
Mega Guru

Hi @MaharshiC ,

 

You suggest the business with a workaround to redirect to the newly created task whenever the ui action is clicked. This way you wont have to deal with the issue of multiple clicks. 

 

If the redirect is not viable then you will need to limit the number of times the ui action can be clicked by checking the session of the user.

 

Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂

-Shantanu

Deborah Brown L
Kilo Sage

Hi @MaharshiC ,

I assume to create a task you are using Glide Record.

If so, add a condition in the Glide Record to check if any task created on the same day/hour/min, if so then no task should be created, otherwise create a new task.

 

Condition example:  gr.addEncodedQuery("sys_created_onONLast minute@javascript:gs.beginningOfLastMinute()@javascript:gs.endOfLastMinute()^ORsys_created_onONCurrent minute@javascript:gs.beginningOfCurrentMinute()@javascript:gs.endOfCurrentMinute()");

 

Regards,

Deborah Brown