Suppose, I need to generate a random number specific to a range. Can I create a Rule-Utility-Function for the same or can I create a data transform implementing some logic and parameterizing the properties.
What would be best approach for the same?
If there is any OOTB function also please let me know.
Thanks and Regards,
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
You could have a Data Transform set an OUT param as shown below.
Set param.IndexOut = java.util.concurrent.ThreadLocalConcurrent.nextInt(param.Start, param.Max + 1)
But from a reuse perspective a Function makes more sense since a Data Transform can call a Function that does the same thing, namely, accept two Integer parameters and return a random Integer that is >= Start and <= Max.
You may want to try like this., but function is recommended from reusability perspective.
Set param.IndexOut = @java("java.util.concurrent.ThreadLocalRandom.current().nextInt(tools.getParamAsInteger(ImmutablePropertyInfo.MODE_STRING,\"Start\"), tools.getParamAsInteger(ImmutablePropertyInfo.MODE_STRING,\"End\"))")
Test compilation failed: ---------- 1. ERROR in /Rule_Obj_Model_AzD_TAUtils_Work_Parent_SetConversionRate_Model_20170927T132257_619_GMT.java (at line 62) tools.putParamValue("RandomNumber", PropertyInfo.TYPE_INTEGER, com.pega.pegarules.priv.FUAUtil.parseInt((tools.getThread().getSystemRandom().nextInt(10)))); ^^^^^^^^ The method parseInt(String) in the type FUAUtil is not applicable for the arguments (int)
I think there is some issue during the data Conversion issue (most likely a bug in Pega). The fact is it should return Java of type Integer but due to some data type conversion it cannot. By adding + " " you are essetially converting the return type to String since contatenation to " " (String) converts the Object to String in java.