Using external javascript libraries in Services

Hi,
We need to run some statistical calculations in a Service and require a specific external JavaScript library (jStat). But when running the Service we receive the error “FunctionEvalError: jStat is not defined”.

The external library is loaded using the custom header tag section in Environment settings (see screen below). We’re not receiving any errors when running/testing the calculations using the jStat library in an app.

I’m only able to find documentation on how to load external libraries to be used in Apps. What is the recommended way to set up an external library so a Service can reach it?

Hi!

Apps and Services run respectively on client and server. The external scripts added to Environment Config are only available on the client. We currently do not support external javascript libraries in Services. This requires another level of security measures, since it’s executed on the server.

However, I’ll register a challenge on that, since it would be very handy in some circumstances!

Thx, but lets say i want to do it client side… or in the action node Import data from file… How do I import it? #noob

Hi!

You just add it in Environment Config → Custom Header Tags

This is adding tags to the Apps, allowing you to add script urls or add javascript code to be put in the header.

What is the status on this challenge? And how might we overcome this challenge ourselves? It is crucial for us to use libraries in Services. @ErikAKSkallevold @kristian

Hi @SinanMaric
Not sure if Appfarm has completed this challenge yet but a possible workaround is to add the library’s content directly into the function where you want to use it. It’s not a pretty solution but it does work (although you get a lot of warnings and errors in the code editor)

In the screenshots below you can see that I’ve added the library’s content before running the final function calls where we use it.


[…]

I hope it helps!

2 Likes

Thank you so much @Kaspar I really appreciate you sharing your code :smile: I will take a look into it!

Hi!

It has not been implemented / prioritized yet.

To our knowledge, a workaround exists, as Kaspar just posted (thanks!). Sorry, that workaround should have been posted initially.

1 Like