on 2025 Feb 06 3:20 PM
As part of our project requirement we want to use generated number with prefix of 'S' and few leading zeros '0000' and number in the end like 1 etc. The expected generated value is like below where there is any insert in to:
Request clarification before answering.
Hello,
the only way i am aware of that would be to implement a custom handler on application level, so in Javascript it could look like this:
this.before("CREATE", "Your entity here", async (req) => {
let newId = 'S00000001;
const { maxID } = await cds.tx(req).run(SELECT.one.from("Your entity").columns("max(internalId) as maxID");
if (maxID) {
const coutner = Number(maxID.substr(1,maxID.length -1));
newId = `S${(counter + 1).toString().padStart(9, '0')}`;
}
req.data.internalId = newId;
});
The above code is just a rough idea, i didn't actually let it run, but something similar to this should probably work.
Cheers
Marco
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.