Example of returning a promise in a custom code action? | Community
Skip to main content
Andrew_Wathen_
Community Advisor
Community Advisor
October 28, 2022
Solved

Example of returning a promise in a custom code action?

  • October 28, 2022
  • 1 reply
  • 2070 views

Hi everyone, looking for some help!

 

This Adobe blog post states "If your Custom Code is JavaScript, then you can now return a promise in conditions or actions. The next condition or action will wait for the promise to resolve before executing."

 

I'm struggling to figure out how to do this.  Has anyone got a simple JavaScript code example they could share? (i.e. return a promise in an action so that the following action waits)

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Anil_Umachigi

Here's something you can try 

 

// action1    
return new Promise(function(resolve, reject) { setTimeout(function() { var thankGodItIsFriday = (new Date().getDay() === 5) if (thankGodItIsFriday) { resolve(); } else { reject(); } }, 1000); }); }

Editing to add article reference: 

Here's a good read around async and an example as well. 

https://www.datanalyst.info/web_analytics/adobe-launch/launch-async-sequential/

1 reply

Anil_Umachigi
Adobe Employee
Anil_UmachigiAdobe EmployeeAccepted solution
Adobe Employee
November 4, 2022

Here's something you can try 

 

// action1    
return new Promise(function(resolve, reject) { setTimeout(function() { var thankGodItIsFriday = (new Date().getDay() === 5) if (thankGodItIsFriday) { resolve(); } else { reject(); } }, 1000); }); }

Editing to add article reference: 

Here's a good read around async and an example as well. 

https://www.datanalyst.info/web_analytics/adobe-launch/launch-async-sequential/