Set Timeout in main.js in the Code Studio Event Action

Hi,

Existing functionality: Added code to navigate to another page after clicking on the Select button, with the Code Studio event action. Page navigation is taking place as soon as the select button is clicked.

Code:

  • pageLink = environment + cs.link(cs.ref(‘page_xxxx’), { ‘context_record_id’: xxxx });
  • cs.redirect(pageLink);

But I need to add at least 3 seconds delay for page navigation.

Background for delay: After clicking on the Select button, the Code Studio Event Action is triggered. Added a code to check if record is available, otherwise trigger the API and get the value. The results are shown on another page, so the page navigation is added in the same code after API is triggered. As the API takes 2-3secs, page navigation is happening before the API completes. So no info is shown on the results page. For this reason, once the API is triggered, if page navigation is delayed by at least 3secs, the API will complete and results can be seen.

I know that we can add a delay with setTimeout() method in frontend.js, but Code Studio Event Action has only the main.js. Upon adding setTimeout() in main.js we are getting the undefined error , please let us know on how to add the delay?..

Thanks in Adavance!..

Regards,
Gopi N.

Hi,

Undocumented but you can try using the below

this.sleep(5) // in second

Hi Gopi,

I think you need to check the response from the API Call first. You cant rely on doing a redirect on fixed number of seconds as you will never be sure how long the API call will take. It may also be unsuccesful.

I would check the response from the API call first and then redirect based on that.