25
Views
9
Comments
Javascript not forming the integer list
Question

I have the below Javascript code that runs in a client action (Action1). Action1 has an output parameter called "numbersList" whose datatype is 'Integer List'. The Action1 is part of another client action called "OnReady" which belongs to a block.

Upon checking the list fetched by the javascript via a variable assignment Var2(whose datatype is 'Integer List')=Action1.numbersList, the list is never formed. Why?


"let numbersList = [];

for (let i = 1; i <= 10; i++) {

  numbersList.push(i);

}"


2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Prabhu,

Not sure with what you try to say with "Action 1 is part of another client action", actions cannot be part of another action, you can call action1 in OnReady action, but it is not part of it.

That said, given that you only shared a bit of your code, can you confirm you also end your javascript logic with:

$parameters.numbersList = numbersList;

Furthermore the javascript code is executed asynchronically, you need to end your javascript logic with $resolve(); to ensure your action flow only continues after the javascript code execution finished.

Furthermore, your sample code starts with " and ends with ", which would make the complete code just a string literal, and it would not execute.

So your code should look like this:

let numbersList = [];

for (let i = 1; i <= 10; i++) {
 numbersList.push(i);
};

$parameters.numbersList = numbersList;

$resolve();

Regards,

Daniel

2023-12-08 17-21-38
Prabhu Sanguthiagarajan

Hi Daniel,

Thanks for quickly looking into this. My bad, what I meant by Action1 to be part of OnReady was actually Action1 is called in OnReady. The "" was only to separate the code from my query. They are not part of the code. 

Based on your revised code, I got the attached error and on double clicking the error, it took me to the segment "$parameters.numbersList" as can also be seen in the attached image.

Am I doing something wrong?


JS error.jpg
2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Your JavaScript node needs an output parameter, I cannot determine from the screenshot of you have it defined with the correct data type.

Also you need the same output parameter defined on action1, and after the JavaScript node an assign where you assign the output parameter from the JavaScript node to the output parameter of action1.

2023-12-08 17-21-38
Prabhu Sanguthiagarajan

Yes. You are right. The JS node was missing the o/p parameter. So, I supplied an o/p parameter to the JS node as "numbersList" with datatype as "Integer List" (actually this datatype was automatically selected). But now I get the error as:

The 'ListType' type is not supported as Output variable types.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

OutSystems does not allow you to define an output parameter of data type list.

Only basic data types are allowed.

So you would need to serialize the javascript array to a JSON string using javascript JSON.stringify()

Then in OutSystems action you can use the JSON Deserialize action to convert the JSON string to a structure of type list

2023-12-08 17-21-38
Prabhu Sanguthiagarajan

Thanks Daniel for igniting the thought process in me to inch closer to the solution. More than the solution I liked the thought process of doing and trying things out.

2023-12-16 19-57-03
Sanjay Kushwah

Hi @Prabhu Sanguthiagarajan,

as @Daniel Kuhlmann suggested  you would need to serialize the javascript array to a JSON string using javascript JSON.stringify(). 

I am attaching the OML achieving list of integers using Javascript.

result: 



Kind regards,

Sanjay Kushwah

ListUsingJavaScript.oml
2023-12-08 17-21-38
Prabhu Sanguthiagarajan

Thanks Sanjay for going the extra mile to send the oml. It helped. Thanks.

2023-12-16 19-57-03
Sanjay Kushwah


You're welcome! I'm glad the OML file was helpful and contributed to solving your problem.

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