How to generate random string and integer in server action.

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

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

@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.

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


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.

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

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

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.

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.

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.


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