Skip to main content
March 8, 2022
Question

Auto generation field

  • March 8, 2022
  • 8 replies
  • 0 views

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
    March 8, 2022

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

    March 8, 2022

    Thank you for your valuable reply :)

    stewart.burchell
    March 8, 2022

    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.

    March 8, 2022

    Thank you for your valuable reply :)

    andrewh0007
    March 8, 2022

    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
            )
          )
        )
      )
    )

    March 9, 2022

    Thank you for your valuable reply

    viraty527193
    March 9, 2022

    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")
            
          

    March 9, 2022

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