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

@MaharshiC 

as soon as the UI action is clicked, try to disable it

are you using that button only in workspace?

if yes then the below approach may not work as DOM may not work there

But it should work in native

Remember this solution will use DOM manipulation and DOM is not recommended

To allow DOM to run in your UI action ensure "Isolate script" field is False

If this field is not on form then from list make it false

It worked for me in native

As soon as I clicked, it added message in console log and the button got disabled

I used this line to disable that in native

document.getElementById('actionName').disabled = true; // give the action name of your ui action here

// your further code here

AnkurBawiskar_0-1747733099677.png

AnkurBawiskar_1-1747733133181.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar,

 

Yes I am using only in workplace not in native.

@MaharshiC 

then DOM won't work.

I don't think any other way to achieve is available for workspace

Solution I shared for native works for me

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@MaharshiC 

you can use a field to check if it was clicked or not

Show the UI action if that field is empty

In your UI action script set that field, insert the task and use current.update() and then reload the form using action.setRedirectURL(current)

Something like this

// new task creation logic

current.u_task_created = true;
current.update();
action.setRedirectURL(current);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar ,

 

We will not be able to add any additional field. Actually they are clicking on the button at the same time multiple times without allowing the form to load so its creating multiple times