Skip to main content
New Participant
Jul 8, 2025 6:22 AM UTC
Question

Getting the same value from a expression rule

Hi all,

I have a process model that calls an expression rule to generate a 6-character random alphanumeric string. I encountered a case where two instances of the process model were triggered at the same time (based on time logs), and both received the same generated value from the expression rule.

I understand that there's always a chance for it to generate the same value. However, I’d like to ask:

Is it possible that both process models used the same instance or execution thread of the expression rule, which might explain why the same value was returned?

    7 replies

    shubhama926776
    Brainy
    Jul 8, 2025 6:27 AM UTC

    No, Expression rules don't share execution threads. Each process instance gets its own separate execution.
    Your random generator likely uses system time as a seed. When two processes run at the exact same millisecond, they get the same seed  -> same random value.

    शुभम्
    New Participant
    Jul 8, 2025 6:37 AM UTC

    Thank you for answering. Is there a way to check this?

    shubhama926776
    Brainy
    Jul 8, 2025 6:39 AM UTC

    Try this code once.

    mid(
      substitute(
        substitute(
          text(now(), "yyyyMMddHHmmssSSS"), 
          ":", ""
        ),
        " ", ""
      ),
      12,
      6
    )


    I would recommend you to use pp!id with now() to make it more unique combination.

    शुभम्
    stefanhelzle0001
    Brainy
    Jul 8, 2025 6:33 AM UTC

    6 characters isn't that much randomness. So, yes, this can happen.

    What do you do with this value?

    New Participant
    Jul 8, 2025 6:40 AM UTC

    We’re using it as an identifier. Unfortunately, we can't add more characters due to an external system limitation.

    stefanhelzle0001
    Brainy
    Jul 8, 2025 6:47 AM UTC

    OK, but then you can't just use a random value. You will get duplicates over time.

    Did you consider to just use the primary key of a record as the identifier? This would guarantee uniqueness. And you can convert that number into an alphanumeric string if needed.

    harshas2775
    Brainy
    Jul 8, 2025 10:27 AM UTC

    Any process instance’s id is unique always! If you want random yet unique string then consider using the process id -pp!id- along with whatever code you have for the random string! 

    Happy to help. Even happier to optimize.