I want to pick random id from List of Ids in outsystems WEB without Javascript

var parsedJsonArray = JSON.parse({Your Json string here});


var randomNumber = parsedJsonArray[Math.floor(Math.random() * parsedJsonArray.length)];


I want to achieve this in Outsystems web

I had the same problem once. Outsystems 10, at leat, don´t provide build-in functions to do it.

I developed a .Net extension to pick a random value in a fix interval and return it.

if you don´t want to do a extension for that, you can search at forge extensions and find a math package that fulfilled your need.

Take careful attention to .net framework before use it, to avoid compatibility issues.

Hello Aravind, checking your description I would do the following:

  1. Use the JSONDeserialize widget to get the list from the JSON to a List that you need to define.
  2. Add an advanced query that returns a default value (Check here). Notice that should be a value between 0 and the lenght of your List (like this you don't need to know any value of the List).
  3. Use an assign where List[ValueOfAdvancedQuery].Value or then use the pre-builted function ListFilter by that index


For the second step, probably there's another solution to do it (Forge plugins or other). However, you can get the results with this solution.

Tiago Gomes wrote:

Hello Aravind, checking your description I would do the following:

  1. Use the JSONDeserialize widget to get the list from the JSON to a List that you need to define.
  2. Add an advanced query that returns a default value (Check here). Notice that should be a value between 0 and the lenght of your List (like this you don't need to know any value of the List).
  3. Use an assign where List[ValueOfAdvancedQuery].Value or then use the pre-builted function ListFilter by that index


For the second step, probably there's another solution to do it (Forge plugins or other). However, you can get the results with this solution.


Thanks for your reply,


I don't want the values between   0 and the length of my List..

instead I need to pick some random values from that list of ids

Hi again,

Notice that if you got a list with 3 elements (id's) you'll get a lenght of 2. If the random query returns me the value 1 (for example) I can get the value of the name using List[1].Name and get this value (in your case it should be the Id). Getting the random index (given by the query) you can automatically access to the random ID.


Solution

Hi Aravind,

There is a component on Forge to generate randomize numbers

https://www.outsystems.com/forge/component-overview/677/randomizer-number-generator


Solution

Tiago Gomes wrote:

Hi again,

Notice that if you got a list with 3 elements (id's) you'll get a lenght of 2. If the random query returns me the value 1 (for example) I can get the value of the name using List[1].Name and get this value (in your case it should be the Id). Getting the random index (given by the query) you can automatically access to the random ID.


I am facing following issue when i use RAND() in sql,

Leandro Correa wrote:

Hi Aravind,

There is a component on Forge to generate randomize numbers

https://www.outsystems.com/forge/component-overview/677/randomizer-number-generator


It Works! Thanks.