Adding javascript libraries to a script so that it can use them

Hello, I was wondering how I would go about adding other libraries to a custom script so that I can interact with external services.
For example, say there’s a service that provides mobile push notifications, and it has a JavaScript library that can be used to send the notifications. Say I want to send a push to a user’s phone when a record is added to a specific table in the database. I understand that I would want to create a script that executes when the event that indicates a record insertion is fired. But I’m not sure how I would load that library so that the functions it exposes would be available to my custom script.

I seem to remember there being some talk in either one of the topics on this community or in one of the blog posts with regards to accomplishing this (adding libraries that scripts can use when they run), but it doesn’t give any detail, and the pages on the Wiki related to server-side scripting are not helpful (some just say “Coming soon…”).

Thanks in advance for the help!

This will be available in the next release, due out in a few days. Any script will be able to include other custom scripts. As an example say my-lib.js is your library script, a custom script on your dsp.

// my-lib.js
function myFunction() {
    return true;
}

Your script can then include that library.

var result;

try
{
    eval(include('my-lib.js'));
    result = 'myFunction() available: ' + myFunction();
} 

catch (_ex )
{
    result = 'myFunction() is NOT available: ' + _ex.message;
}

return result;
2 Likes

Sounds awesome! This will be incredibly helpful.

Just wondering if you can share with us what lib you are using for push notifications? Thanks.

It this mean that we will able to include javascript url libraries as well?

Currently it only works with files in local storage not URL’s.

Where can I upload libraries to so my server side scripts can access them?
I want to upload jQuery.

We have not tested with jQuery specifically, but basically you would create a new custom script named jQuery. The file name created in local storage will be jQuery.js. Then you can include this library in your main script, as shown above.