19
Views
9
Comments
Solved
How to use a "Text List" as input to javascript
Question

Hi,

I have a list of client names(Type "Text") that i want to pass as an input parameter to a javascript and inside, i want to iterate for each of the client names.

As i can see Javascript in outsystems doesnot allow a List as an input parameter. Is there a workaround to pass a list into the javascript?

Thanks

Rank: #54
Solution

Hi LearnIt,


You can use the JSONSerialize from the left sidebar to transform the list in a JSON text, like on the image below:



And then you can use the text output as an input on your Javascript.


Kind Regards,
João

Rank: #8626

Thanks João . I got it this far in my project and i have received the list as a string inside the JS.

But I am not able to convert this into a list inside JS. Can you help me with the function name that i can use to split this string ("["Listvalue1","ListValue2"]") into a list of 2 attributes.

Thanks

mvp_badge
MVP
Rank: #17

In JavaScript:

you can use JSON.parse to generate a JSON object from a JSON string

and JSON.stringify to generate a JSON string from an JSON Object

Regards,

Daniel

Rank: #493
mvp_badge
MVP
Rank: #17

No, he wants to convert the JSON string into JSON object

Rank: #8626

Thanks Daniel for the solution. This worked for me. But since João has solved my real problem, i would mark his answer as the solution. Hope you dont mind.

Thanks for your help. Really appreciate it

mvp_badge
MVP
Rank: #17

No problem, João is my colleague :)

Did you know you can mark more than one solution as a solution to your problem?

This is possible since the revamped Forum update from some months ago.

Rank: #87

Hi Learn iT,

can you let me know why you want JS for it , because already you have a text list and you can use loop on it  and get each client name from in it.


Regards
Rahul

Rank: #8626

Hi Rahul,

I have some custom process that i am running inside this javascript and i want this to run for each Client. Thats why

Rank: #54
Solution

Hi LearnIt,


You can use the JSONSerialize from the left sidebar to transform the list in a JSON text, like on the image below:



And then you can use the text output as an input on your Javascript.


Kind Regards,
João

Rank: #8626

Thanks João . I got it this far in my project and i have received the list as a string inside the JS.

But I am not able to convert this into a list inside JS. Can you help me with the function name that i can use to split this string ("["Listvalue1","ListValue2"]") into a list of 2 attributes.

Thanks

mvp_badge
MVP
Rank: #17

In JavaScript:

you can use JSON.parse to generate a JSON object from a JSON string

and JSON.stringify to generate a JSON string from an JSON Object

Regards,

Daniel

Rank: #493
mvp_badge
MVP
Rank: #17

No, he wants to convert the JSON string into JSON object

Rank: #8626

Thanks Daniel for the solution. This worked for me. But since João has solved my real problem, i would mark his answer as the solution. Hope you dont mind.

Thanks for your help. Really appreciate it

mvp_badge
MVP
Rank: #17

No problem, João is my colleague :)

Did you know you can mark more than one solution as a solution to your problem?

This is possible since the revamped Forum update from some months ago.