Using third-party javascript libraries on Web application hosted in Adobe Campaign is simple. It’s as easy as hosting them on some public URL or in the resource folder within Adobe Campaign. Then, calling them on a web application using <script> tags. Now, what about workflows that execute javascript on the server-side?
At times, we know a task is pretty straight forward and easy to implement, if we use well tested external javascript library rather then recreating the wheels. Additionally, it will increase productivity and reduce the testing effort.
There are many good libraries available that come with implementations that could be very handy while working on some of the complex manipulations within a workflow or even personalization. That includes:
- Moment.js – date library for parsing, validating, manipulating, and formatting dates
- Underscore.js – working with map, filter, invoke, function binding, javascript templating, creating quick indexes
- Hash table – working with hash, hash map, unordered map or dictionary
- Lodash – working with arrays, numbers, objects, strings, etc
So, here are simple steps that can help you leverage these libraries within Adobe Campaign to address scenarios quite efficiently.
Step1: Download complete library
Browse the CDN URL of the library you want to use and download it to your local system. For this demo purpose, we are using moments.js hosted on URL:
https://cdn.jsdelivr.net/npm/moment@2.27.0/moment.min.js
Step 2: Add library to Javascript Codes folder
Go to Javascript Code folder and create a new one named ‘lib:moment.js”. Paste the code you downloaded (in step#1) and save the javascript code entry.
Location: Administration > Configuration > JavaScript codes
**Assuming you have admin rights to proceed with this step.
Step 3: Load library in javascript activity and use
Use “loadLibrary()” method to load the external library and straight away jump to address your scenario just like any other out-of-box standard library functions.
Enjoy!!