Skip to main content
Andrew_Wathen_
Community Advisor
Community Advisor
Oct 28, 2022 4:16 PM UTC
Solved

Example of returning a promise in a custom code action?

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.
Anil_Umachigi
Anil_UmachigiAccepted solution
Adobe Employee
Nov 4, 2022 5:06 AM UTC

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
Nov 4, 2022 5:06 AM UTC

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/

Translate