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

J Siva
Tera Sage

Hi @MaharshiC 
try the below script to set a delay of 10 seconds beofre executing the main logic.

var setTimer = setTimeout(setTimerDelay, 10000); 
function setTimerDelay() {
    alert('10 Seconds delay');{
		//Your logic here
	}

}

Regards,
Siva

MaharshiC
Tera Contributor

Hi @J Siva , 

Do I put the entire logic of ui action after the alert?

 

Regards,

Maharshi chatterjee

@MaharshiC 

can you share your UI action script?

is it client side or server side?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

This is the UI Action

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);
        });
    }
}