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
  • Stewart gave a good solution, but I'd also be curious how you plan to use this. Like do you actually need the value in the database or are you just hoping to have a friendly way of displaying the PK in Appian? If it's the latter, I'd recommend just storing the integer in the database and then have some method of formatting the result in Appian. For example, you could create a custom field that concatenates an app name in front of the identifer and it should work perfectly.

Reply
  • Stewart gave a good solution, but I'd also be curious how you plan to use this. Like do you actually need the value in the database or are you just hoping to have a friendly way of displaying the PK in Appian? If it's the latter, I'd recommend just storing the integer in the database and then have some method of formatting the result in Appian. For example, you could create a custom field that concatenates an app name in front of the identifer and it should work perfectly.

Children