Generating Alpha-numeric String using Groovy
2023-11-10 17:37:53 Author: blogs.sap.com(查看原文) 阅读量:8 收藏

Generating Alpha-numeric String using Groovy

Steps to generate an alphanumeric string of length 8 using groovy.

  1. Create a basic Iflow.
  2. Add Groovy to generate alphanumeric string of length 8.
    import com.sap.gateway.ip.core.customdev.util.Message
    import java.security.SecureRandom

    def 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
    }

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

  1. In Content modifier use this syntax to print custom timezone date and time.

${in.body}${date-with-timezone:now:IST:ddMMyyyyHHmmssS}

  1. Add Start point and end point in the iflow for simulation.
  2. Click on simulation tab to run the simulation.
  3. Once the simulation done click on the end message box to check the reference id.
  4. We are getting the reference id of length 25 which consist of 8 random alphanumeric string and current date with timezone.

Thanks

Dushyant


文章来源: https://blogs.sap.com/2023/11/10/generating-alpha-numeric-string-using-groovy/
如有侵权请联系:admin#unsafe.sh