cancel
Showing results for 
Search instead for 
Did you mean: 

Personas 2.0 - Adding a pause to a script

shane_kelly2
Participant
0 Kudos

We have a script button that goes to another transaction - and creates an output - but the record is locked while the output is being created.

Is there a way to add a pause into a script for a second or two so that it has a chance to create the output, and unlock the record?

Accepted Solutions (0)

Answers (2)

Answers (2)

chinthan_yajamaan
Active Contributor
0 Kudos

You can try adding nested for loops with empty steps in javascript. Like

for (var i=0; i< 100000; i++){

     for(varj=0; j< 100000; j++){

          //Just waiting

     }

}

shane_kelly2
Participant
0 Kudos

thanks Chinthan - we were thinking of trying that too...any idea how long a 100,000 step loop takes to run?

chinthan_yajamaan
Active Contributor
0 Kudos

You can check time at beginning and end of loop to see the total time taken.

eg:

var start = (new Date()).getTime();

......

var end= (new Date()).getTime();

total = (end-start)/1000

shane_kelly2
Participant
0 Kudos

when I try this - i get the same 'javascript error'

chinthan_yajamaan
Active Contributor
0 Kudos

can you check the console or provide your javascript code?

0 Kudos

any reason for not using settimeout??

Edit fiddle - JSFiddle

Former Member
0 Kudos

I am not sure if the execution will still goes to the next bock in the script button before timeout. Nice to try out anyway.

Dong

shane_kelly2
Participant
0 Kudos

we're not sure why - but every javascript command we put in our script causes it to fail...

but we found another way... we added a step to jump to a different transaction and then jump back to the original transaction - this took just enough time for the background job to complete

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

You could call a webRFC which waits before passing control back to the script.

shane_kelly2
Participant
0 Kudos

can you use the JavaScript sleep(5); command?  or does the JavaScript option only allow for arg calculations?

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

I never tried that but it should work... give it a shot