Apply transformers directly on variables

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Apply transformers directly on variables

L4 Transporter

Hello,

I'm creating Json lists introducing data in them. I'm using "addToList" automation. The data introduced example:

listData:

{"key1":{

"subkey1: ${dataInput1},

"subkey2: ${dataInput2},

"subkey3: ${dataInput3},

"subkey4: ${dataInput4}

}

 

Is there a way to transform the variables directly in the input listData with no need to create a set for each dataInput?

 

1 REPLY 1

L3 Networker

Hi @Josep 

The simple answer to your question is yes, you can use transformer to write for loop to get each ${datainput} value but it's not quite simple. You will need to utilize DT (General) and to write JavaScript for loop code.

 

For the task, Get = ${dataInput} assuming this is a simple list with different items instead of a Json object.

For the Transformer, here is what you would enter:

.=>val.map(function(elem){

my_str="subkey";

tags=elem{'dataInput};

tagnames="";

for(i=0;i<tags.length;i++){

my_str=my_str+i=","

tagnames=tagnames+tags[i]+",";}

return {my_str.slice(0,-1):tagnames.slice(0,-1)}})

 

Obviously, I cannot guarantee that this DT will work for your incident since there are a few variables that I would need to know and this will require testing in your instance. I would suggest to play around with DT.

 

Good luck!


Yuki

  • 1084 Views
  • 1 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!