New Code Service - Run Custom JavaScript

(John Jackson) #1

This is really, really powerful for those of you who know JavaScript. You can now use our new Code service to execute custom JavaScript (taking input from the trigger or other actions), and output a result which you can then use in the rest of the flow.

Take a look at our Code Documentation to get started.

(Perry Ismangil) #2

Sounds great!

How do we use our authenticated CapsuleCRM account?

Or do we need to re authenticate using API key? Is the inputs a safe place
to put API keys?

(John Jackson) #3

You will have to either hardcode the API key inside the script, or pass it in as an input.

We encrypt credentials securely for all your service auths but I will need to check if we encrypt the contents of scripts, or indeed the inputs to them.

(Perry Ismangil) #4

The sample code in doc missing end parenthesis

utils.request(opts, function(err, resp, body) {
  if(err) { 
    return reject(err);


(John Jackson) #5

That’s fixed. I was only moaning about example code not being tested on another site a few days ago!

I’ll make a note to try all three examples there over the weekend.

Really appreciate the feedback!

(Perry Ismangil) #6

How to do output to log?

It’s about the only way to debug :slight_smile:

(John Jackson) #7

Logging is one drawback, of course you get many more options when you create scripts in an IDE and run them locally. I’d first suggest that - if you can, create and test your scripts somewhere more suitable then use the script in Flow XO.

If not, you can either use reject("Your error message") to save something to the log, or send some debug info (maybe an object) to resolve which will then show up as the output.

1 Like
(Perry Ismangil) #8

This is what I mostly did, there does seem something specific to FlowXO behaviour, for example I’m trying to have a boolean variable as output


When flag is true I get ‘true’ when flag is false I get {}

(Deibys Paredes) #9

Hi, John.

I’m trying to run a Custom JavaScript, but it doesn’t work. When we are in the piece of code the bot doesn’t do anything. Below I send you our code we are using.


var rut = {{pregunta_rut_clave.parsed_answer}}
var valor = rut.split(’.’).join("");
valor = valor.split(’-’).join("");
cuerpo = valor.slice(0, -1);
dv = valor.slice(-1).toUpperCase();
rut = cuerpo + ‘-’ + dv;

if (cuerpo.length < 7) {
    return reject("No es valido el Rut");

suma = 0;
multiplo = 2;

for (i = 1; i <= cuerpo.length; i++) {
    index = multiplo * valor.charAt(cuerpo.length - i);
    suma = suma + index;
    if (multiplo < 7) {
        multiplo = multiplo + 1;
    } else {
        multiplo = 2;

dvEsperado = 11 - (suma % 11);
dv = (dv == 'K') ? 10 : dv;
dv = (dv == 0) ? 11 : dv;

 if(dvEsperado == dv) {
   return resolve("Es valido el rut")
 } else {
   return reject("No es valido el Rut);

Thanks in advance.

(Daniel Beckett) #10

The best place to start when troubleshooting any problems with the code service is to check your interactions. This will list any errors and give you a better idea of what’s going wrong.

There’s also some free web-based services that can help with finding any problems with the code. JSLint for example.