Hello, I need help to use different JS functions in my workflow.
For example, the String.startsWith() function does not work, it tells me the function does not exist.
Are JavaScript functions limited in Adobe Campaign? How can I use them properly? Where can I read about what functions are available?
Solved! Go to Solution.
Some functions are not available or not compatible with the specific version of JavaScript used in Adobe Campaign.
Regarding the String.startsWith() function, it is part of ECMAScript 6 (ES6) and may not be available in some older versions of JavaScript.
To check your version of JavaScript, you can run the following code: console.log("JavaScript version:", typeof Symbol());-
If the output is "function", then you are using ES6 or a later version of JavaScript. If the output is "undefined", then you are using an older version of JavaScript.
Make sure that you are calling the function on a string object, and not just as a standalone function.
For example, you should call "hello world".startsWith("hello"), not just startsWith("hello").
Specifically, the JavaScript API documentation provides information on the available functions and how to use them.
Hello @CampaignerForLife
Adobe Campaign does not support all JS functions.
However, you can use regex to do the same thing. Here is an example.
var firstTheChars= /^.{3}/;
var text = 'mylongString is here';
var textStartWith="myl";
var result = text.match(firstTheChars);
if(result==textStartWith){
// do something here
}
Some functions are not available or not compatible with the specific version of JavaScript used in Adobe Campaign.
Regarding the String.startsWith() function, it is part of ECMAScript 6 (ES6) and may not be available in some older versions of JavaScript.
To check your version of JavaScript, you can run the following code: console.log("JavaScript version:", typeof Symbol());-
If the output is "function", then you are using ES6 or a later version of JavaScript. If the output is "undefined", then you are using an older version of JavaScript.
Make sure that you are calling the function on a string object, and not just as a standalone function.
For example, you should call "hello world".startsWith("hello"), not just startsWith("hello").
Specifically, the JavaScript API documentation provides information on the available functions and how to use them.
You can use the function ".charAT" to check for the string.
var str = 'ABC12323';
var first = str.charAt(0);
if (first.match(/[a-z]/i))
{
logInfo("It is String.");
}
else
{
logInfo("It is Numeric.");
}
Regards
Akshay
JavaScript functions in Adobe Campaigns may be limited depending on the context in which they are used. It's possible that the specific version of Adobe Campaign you're using may not support the String.startsWith() function, or that it's not available in the particular part of the code you're working with.
Use this link for Javascript API to read about it.
https://experienceleague.adobe.com/developer/campaign-api/api/p-1.html
An alternative could also be to create a custom functions JS code through (Administration/Configuration/Javascript codes/) and write your custom function and call it whereever required by loading the library as such;
Say your custom javascript code page is named adb:myFunctions.js and has the following custom function
//startsWith function
function startsWith(i,s) {
return s.indexOf(i) === 0;
}
In your workflow/webapp or whereever you are going to load your custom functions as such
loadLibrary("adb:myFunctions.js");
Then in your code
var myString = "hello world";
logInfo(startsWith("hello",myString));
which is going to return true or false
In a realistic scenario;
var i = startsWith("hello",myString);
if (i == true){//dosomething};
Views
Likes
Replies