Code not working

(Dominik Teiml) #1

Hi, I use a webhook to GET an online JSON sucessfully (I know). Then I ask a user a question. Then I am running the following code.

Inputs:
a = {{webhook result}}
b = {{question result}}

And my code is:
var a = inputs.a;
var b = inputs.b;
var result = a.b;
resolve(result);

then I have a message with content {{code result}}, I have a very simple JSON of the form
{
“X”:“x”,
“Y”:“y”,
“Z”:“z”
}
and the answer to the question is “X”, so the bot should say “x”, however I get no such message from the bot.

Any ideas? I’ve been stuck on this for a while

(John Jackson) #2

You should be able to see in the log where the logic falls down? Is it the code service?

If you could post some info from the log that would help.

Hopefully we can figure it out :grinning:

(Dominik Teiml) #3

Hey John, I checked the log for my code: Executed successfully with Inputs as

{
“a”: “{“one”:“Singular sensation”,“two”:“Beady little eyes”,“three”:“Little birds pitch by my doorstep”}”,
“b”: “one”
}

I realised the json is passed as a string, so I changed my code to:

var a = JSON.parse(inputs.a);
var b = inputs.b;
var result = a.b;
resolve(result);

However, it still doesn’t work.

The logs say the code is executed successfully, but the “Message can’t be blank” in the next step.

Thanks

(Dominik Teiml) #4

Hey John, do you have any ideas how to solve that? Unfortunately I can’t continue with my bot until this is solved :frowning:

(John Jackson) #5

The Message can't be blank tells me your input into the next action (send a message?) is empty?

So I think you should look at what the output is from the code action and what the input is to the next action.

Could you post up a log of that if possible?

(Dominik Teiml) #6

I just did. I sent you the log of my code.

The log just says the code and Inputs, it does not say the outputs.

What should I change the code to so it works?

(John Jackson) #7

If there is no output showing in the log, I would guess that this:

resolve(result);

Might result in null. I would check your code to make sure it gives you the result you expect.

I can see that result = a.b;, but I can’t see a property b of a?