Auto Generate primary ID using a custom prefix

Certified Senior Developer

Hello,

I would like to create a CDT with a primary key which must be an Auto-generated value but with a prefixed value. 

Ex: "APP_01",

Where the number 01 must be an auto incremented value. Is it possible to do so? If yes please suggest me a possible way to do it.

I was unable to understand the following:

Generating primary keys

When using a sequence to generate ids (such as @GeneratedValue(strategy=GenerationType.SEQUENCE)), we recommend allowing the system to name the sequence instead of providing a name with the generator attribute. If you choose to define a sequence generator with the generator attribute in conjunction with the @SequenceGenerator annotation, then you must provide a name, and that name must be unique across all sequence generators in the system to avoid uniqueness constraint violations

https://docs.appian.com/suite/help/22.2/Database_Schema_Best_Practices.html

Please help me with the above.

  Discussion posts and replies are publicly visible

Parents
  • You could roll your own solution to this. You could create a database table that has a column to hold the prefix e.g. 'APP' in your example, and then another column that holds the latest sequence number e.g. '01' in your example, and then write a Stored Procedure that takes those two values, increments the number part of it and writes that back to the same table, and then returns the concatenation of those two values. You can then call that Stored Procedure from Appian and use the returned value as your custom key for use where you intend to use it.

Reply
  • You could roll your own solution to this. You could create a database table that has a column to hold the prefix e.g. 'APP' in your example, and then another column that holds the latest sequence number e.g. '01' in your example, and then write a Stored Procedure that takes those two values, increments the number part of it and writes that back to the same table, and then returns the concatenation of those two values. You can then call that Stored Procedure from Appian and use the returned value as your custom key for use where you intend to use it.

Children