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

mvp_badge
MVP
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

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

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

mvp_badge
MVP

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

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

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.

mvp_badge
MVP

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

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

mvp_badge
MVP
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

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

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

mvp_badge
MVP

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

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

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.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.