Skip to main content
August 19, 2022
Solved

Custom Auto-Generated Sequences in Appian

  • August 19, 2022
  • 5 replies
  • 0 views

Hi

I started working from the last month as Appian developer

Need help or suggestion

Tying to implement custom autogenerated primary key in sequence.

Example - INVREQ0001 , INVREQ0002 and so on.

If someone knows how to generate this then please let me know

Many Thanks in advance

    Best answer by csteward

    As Stefan suggests, I would let the DB auto-increment an integer primary key, then format it this way to display for the user.  You can even save the formatted text back to the DB based on the primary key if you want.

    a!localVariables(
      local!id: 2,
      
      concat(
        "INVREQ",
        repeat(4-len(local!id),"0"),
        local!id
      )
    )

    Or, with similar logic, store the ID value (integer) in a constant within the application, at the start of each request, use the Increment Constant smart service to increment it and pull the new value to format into the ID value with "INVREQ__".

    5 replies

    harshitb6843
    August 19, 2022

    Hi there,

    I don't think that is possible. Tho you can do it with plain numbers, with a jump too e.g. 10,20,30...n (after 22.3) but mashing it up with some custom characters will be not straightforward. 
    So you will have to check for the last data in the table, add one to it and then concat your characters. 

    stefanhelzle0001
    Brainy
    August 19, 2022

    Does this need to be stored in the database or can it be just showed to the user this way?

    August 19, 2022

    its read-only field

    I only want to create this on the database side.

    csteward
    cstewardAnswer
    August 19, 2022

    As Stefan suggests, I would let the DB auto-increment an integer primary key, then format it this way to display for the user.  You can even save the formatted text back to the DB based on the primary key if you want.

    a!localVariables(
      local!id: 2,
      
      concat(
        "INVREQ",
        repeat(4-len(local!id),"0"),
        local!id
      )
    )

    Or, with similar logic, store the ID value (integer) in a constant within the application, at the start of each request, use the Increment Constant smart service to increment it and pull the new value to format into the ID value with "INVREQ__".