Skip to main content
New Participant
Mar 8, 2022 10:18 AM UTC
Question

Auto generation field

Hi,

I've been creating an application for onboarding clients. For this I want to create an auto generated field in CDT. whenever a new client register for onboarding and successfully submits the form, automatically the unique onboarding number have to create for every client.

Is it possible to create?

Thanks in advance.

    8 replies

    gopalk2865
    Participating Frequently
    Mar 8, 2022 10:25 AM UTC

    HI, You can create a field called "ID" in the CDT and while configuring you can check mark for Auto generation option.

    New Participant
    Mar 8, 2022 10:30 AM UTC

    Thank you for your valuable reply :)

    stewart.burchell
    Employee
    Mar 8, 2022 10:27 AM UTC

    So to be clear: you want to auto-generate a unique Reference Number for each onboarding process instance? The way I've done this in the past is to have a database table that stores a sequence number, and a stored procedure that increments and then returns the sequence number. The actual reference number might be constructed from, say, a date and the sequence number itself e.g. 20220300005 - that is, the year 2022, the month of March (03) and sequence number 00005. Your stored proc would also determine if the currently stored sequence number is for a different month and, if so, reset the sequence to 1. 

    Using a table allows you re-use it for other sequence numbers for other contexts i.e. it could be a shared service across multiple applications.

    New Participant
    Mar 8, 2022 10:31 AM UTC

    Thank you for your valuable reply :)

    andrewh0007
    Inspiring
    Mar 8, 2022 9:39 PM UTC

    I use this function when generating a unique identifier.

    a!localVariables(
      local!raw: a!refreshVariable(
        value: concat(
          dec2hex(toint(rand(4)*256),2),
          "-",
          dec2hex(toint(rand(2)*256),2),
          "-",
          dec2hex(toint(rand(2)*256),2),
          "-",
          dec2hex(toint(rand(2)*256),2),
          "-",
          dec2hex(datetext(now(),"yyyy"),3),
          dec2hex(datetext(now(),"MMdd"),3),
          dec2hex(datetext(now(),"HHmm"),3),
          dec2hex(datetext(now(),"SSss"),3)
        ),
        refreshAlways: true
      ),
      local!rawLength: len(local!raw),
      concat(
        a!forEach(
          items: 1 + enumerate(local!rawLength),
          expression: a!localVariables(
            local!currentCharacter: index(
              local!raw,
              fv!item,
              {}
            ),
            if(
              a!isNullOrEmpty(
                stripwith(
                  lower(local!currentCharacter),
                  "abcdefghijklmnopqkstuvwxyz"
                )
              ),
              if(
                rand(1) < 0.5,
                lower(local!currentCharacter),
                local!currentCharacter
              ),
              local!currentCharacter
            )
          )
        )
      )
    )

    New Participant
    Mar 9, 2022 5:51 AM UTC

    Thank you for your valuable reply

    viraty527193
    Inspiring
    Mar 9, 2022 11:36 AM UTC

    Hi in order to autogenerate the value in any column (in normal use case it is the primary key of the CDT "id") use @GeneratedValue annotation in the xsd

    in the database table mark the value as autoincrement. 

    This will create a new autoincrement value each time a transaction is made.

    It should look something lie this

    
            
              @Id @GeneratedValue @Column(name="databaseColumnName", nullable=false, unique=true, columnDefinition="INT")
            
          

    New Participant
    Mar 9, 2022 2:41 PM UTC

    Thank you for your valuable reply... It works well