cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Data transformation using Javascript Connector

jani-swinnen
Deputy Chef I
Deputy Chef I

Hi all,


I'm currently trying to do some data transformation using the Javascript connector but I can't figure out how to corrrectly configure the output. I'm trying to format a JSON body for a HTTP request to the Slack chat.scduleMessage endpoint.


In my recipe I set a variable to a JSON string, which I need to input into the Javascript connector, I then use JSON.parse to parse this string, but when I return the JSON.stringify on the next line, it ends up as a null value... My output schema is just a string named payload and in the next step the payload datapill is an empty string.


The JSON.parse does not give me an error so I have to assume the string gets parsed, but somehow, somewhere it ends up as null.


Does anyone have any experience in this situation?

1 ACCEPTED SOLUTION

gary1
Executive Chef III
Executive Chef III

I just ran a quick test and was able to get JSON.parse and JSON.stringify to work without issue. It might be how your script is returning the output. I found that part a bit tricky when first working with the JS connector.

I attached some images of my setup and script so you can see how it works and hopefully replicate it.

js_connector.png

js_log.png

โ€ƒโ€ƒ

js_output.png

โ€ƒ

View solution in original post

5 REPLIES 5

gary1
Executive Chef III
Executive Chef III

I just ran a quick test and was able to get JSON.parse and JSON.stringify to work without issue. It might be how your script is returning the output. I found that part a bit tricky when first working with the JS connector.

I attached some images of my setup and script so you can see how it works and hopefully replicate it.

js_connector.png

js_log.png

โ€ƒโ€ƒ

js_output.png

โ€ƒ

Hello Gary,

I am Jagadeesh. I am working on the same Usecase that Jani was explaining. I wanted to refer to your setup and Script but I couldn't find the attached images. Could you please share them once again?

Thanks in Advance.

Hi @Saichand,

I have updated Gary's replies with the original screenshots of his solution. I have also attached them to this reply (see below).

Thank you,
Meghan

js_connector.png

js_log.png

โ€ƒ

js_output.png

โ€ƒโ€ƒ

jani-swinnen
Deputy Chef I
Deputy Chef I

Thank you Gary,


I managed to figure it out with the help of your screenshots.


The problem was that I changed the syntax when trying to fix a previous bug, and in doing so I removed the curly braces surrounding the input and return values. I think that's the main reason for my function to return a null value.