Generating Alpha-numeric String using Groovy
Steps to generate an alphanumeric string of length 8 using groovy.
- Create a basic Iflow.
- Add Groovy to generate alphanumeric string of length 8.
import com.sap.gateway.ip.core.customdev.util.Message
import java.security.SecureRandomdef Message processData(Message message)
{def UniqueString = generateRnadomKey()
message.setBody(UniqueString)
return message
}def generateRnadomKey()
{
def chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″
def random = new SecureRandom()
def key = ”
for(int i = 0; i<8; i++)
{
int index = random.nextInt(chars.length())
key += chars[index]
}
return key
} - Suppose we have generate a reference id of length 25 consist of 8 random alphanumeric string and current date with timezone.
Example:
Suppose we have random string is 8yu78H1e and current date with timezone value 10112023144952324.
The final output will be 8yu78H1e10112023144952324.
- In Content modifier use this syntax to print custom timezone date and time.
${in.body}${date-with-timezone:now:IST:ddMMyyyyHHmmssS}
- Add Start point and end point in the iflow for simulation.
- Click on simulation tab to run the simulation.
- Once the simulation done click on the end message box to check the reference id.
- We are getting the reference id of length 25 which consist of 8 random alphanumeric string and current date with timezone.
Thanks
Dushyant