How to use Promise in javaScript activity

Avatar

Avatar

JamesAlio

Avatar

JamesAlio

JamesAlio

02-04-2021

Hello,

i want to use the following code in a javascript activity but im getting an error : 

var myPromise = new Promise(function(myResolve, myReject) {
  setTimeout(function() { myResolve("I love You !!"); }, 3000);
});

myPromise.then(function(value) {
 logInfo('Helllo Promise : '+value);
});

 

this is the error that i get :  02/04/2021 16:02:11 js7 JST-310000  ligne 2 : Promise is not defined.

 

do you have any solution please ?

Thanks in advance.

Accepted Solutions (0)

Answers (3)

Answers (3)

Avatar

Avatar

Milan_Vucetic

MVP

Avatar

Milan_Vucetic

MVP

Milan_Vucetic
MVP

05-04-2021

Hi @JamesAlio

it is not there by deafult.

You may try create a new JS library and copy code from here for example.

Finally, load library in your JS node or connector via loadLibrary("your_schema:Your_new_file.js");

 

This is not tested. If code does not work for you try with different ones (look for min.js extension)

Regards,

Milan

Avatar

Avatar

marcinkacz

Avatar

marcinkacz

marcinkacz

2 hours ago

Hi James,

I guess Promise doesn't work in Adobe Campaign. ACC Javascript implementation is Spider Monkey, so it is probably ECMAScript 5 (2009) standard. Promises were introduced with ECMA 6 (ECMAScript 2015).

Regards, Marcin

Avatar

Avatar

Sukrity_Wadhwa

Employee

Avatar

Sukrity_Wadhwa

Employee

Sukrity_Wadhwa
Employee

13-04-2021

Hi @JamesAlio,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know.

Thanks!