5997
Views
17
Comments
How to generate random string and integer in server action.
Question

How to generate a random string and integer in server action. To add excel file name unique value while extracting the file.

2025-12-11 08-02-29
Ferhat Karatay

Hi Sachin,

You can check the built-in Guid function.
It generates a random Guid string. It's a long text however you can use substring to minimize it.

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/System_Actions#GenerateGuid

Hope it helps.

With best regards,
F.Karatay

UserImage.jpg
Robert Johnston

Ferhat Karatay wrote:

Hi Sachin,

You can check the built-in Guid function.
It generates a random Guid string. It's a long text however you can use substring to minimize it.

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/System_Actions#GenerateGuid

Hope it helps.

With best regards,
F.Karatay


Hello Ferhat,

Even unique id also fine, Working as excepted Thank you.

2020-09-15 13-07-23
Kilian Hekhuis
Ā 
MVP

@Ferhat: That's bad advice! GUIDs are unique, but they are definitely not random! And taking a substring of a GUID is even worse, as parts of it are explicitly not unique!

@Sachin: There are several Forge components that allow you to generate random integers and/or strings.

UserImage.jpg
Robert Johnston

Kilian Hekhuis wrote:

@Ferhat: That's bad advice! GUIDs are unique, but they are definitely not random! And taking a substring of a GUID is even worse, as parts of it are explicitly not unique!

@Sachin: There are several Forge components that allow you to generate random integers and/or strings.

Hello Killian,

  Instead of forge component can we run javascript and get the random value? In server action.

Regards,

Sachin


2020-09-15 13-07-23
Kilian Hekhuis
Ā 
MVP

Hi Sachin,

JavaScript runs client side. It doesn't run server side, there's no server side JavaScript with the OutSystems Platform. You cannot run JavaScript in a Server Action*. Why would you want to use JavaScript?

*Yes, there's RunJavaScript from the HTTPRequestHandler, but it doesn't do what you'd probably expect.

UserImage.jpg
Robert Johnston

Kilian Hekhuis wrote:

Hi Sachin,

JavaScript runs client side. It doesn't run server side, there's no server side JavaScript with the OutSystems Platform. You cannot run JavaScript in a Server Action*. Why would you want to use JavaScript?

*Yes, there's RunJavaScript from the HTTPRequestHandler, but it doesn't do what you'd probably expect.


Hi Killian,


Without Forge components, Not there any builtin function? Like as suggested Ferhat


Regards,

Sachin

2020-09-15 13-07-23
Kilian Hekhuis
Ā 
MVP

No, there's nothing built-in to use. But there's nothing wrong with using Forge Compents!

UserImage.jpg
Robert Johnston

Kilian Hekhuis wrote:

No, there's nothing built-in to use. But there's nothing wrong with using Forge Compents!


Hi Kilian,

 

Thank's for the information.


2020-09-15 13-07-23
Kilian Hekhuis
Ā 
MVP

Yes, if you need just a unique, not a random, sequence of characters, using the built-in GenerateGuid is fine. But like I said, it is not random, and you should not expect parts of it to be random.

2018-07-06 11-13-55
Nathan Hobbs

Outsystems already has built in functionality to generate random passwords.

It takes 2 parameters... the number of character you want and if it should include letters as well as numbers:


https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Miscellaneous

UserImage.jpg
herman-z

Hi, I am building a mobile screen to:

1. Generate a random number 

2. Add a record to a table with that random number

3. Display that random number on screen

I read the doc link above but I am not able to find the GeneratePassword function. Could you please give me some pointers how/where to insert this function call in the 1st step?

Thanks!

Herman

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

Hi,

You do not see the function as it is a build in function only available in server actions.

If you want to generate a random string of length of your choice in JavaScript, you can add a JavaScript node with the following code and and an input parameter TextLengthnof type integer and an output parameter of type text called Uid to it.

Regards,

Daniel

function getRandomString(length) {
  var s = '';
  do { s += Math.random().toString(36).substr(2); } while (s.length < length);
  s = s.substr(0, length);
  
  return s;
}

$parameters.Uid = getRandomString($parameters.TextLength);
UserImage.jpg
herman-z

Hi Daniel,

Thanks for your answer. I am quite new to OutSystems and am still feeling things around. 

On that screen, I should add Input, Output Param, a ClientAction on Initialize. Inside the ClientAction, I should add the Javascript node, and then the CreateOrUpdate Server Action to insert the record?

Herman

UserImage.jpg
Clement Louis

Herman Z wrote:

Hi Daniel,

Thanks for your answer. I am quite new to OutSystems and am still feeling things around. 

On that screen, I should add Input, Output Param, a ClientAction on Initialize. Inside the ClientAction, I should add the Javascript node, and then the CreateOrUpdate Server Action to insert the record?

Herman


Hi Herman,


You need to add the input and output parameter for the javascript node that you use in your client action.


Regards,

Clement

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

Hi Clement,

Here is a demo mobile app in which it is implemented.

I made it a reusable client action that is used in the screen.

Regards,

Daniel

RandomStringDemo.oap
UserImage.jpg
herman-z

Thank you Clement and Daniel for your answers and Daniel, you even posted a .oap, thanks a lot!!

I am able to solve the problem I have.

Off topic, if I have to insert a record into a table on mobile screen load, what's a good practice? Run a SQL stored procedure or use the CreateXXX function?

Herman

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

Hi,

Glad I could help.

Best practice is to use the entity actions that OutSystems provide. 

Regards,

Daniel

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