Adding Custom Logic

This commit is contained in:
2026-07-26 12:33:10 +00:00
parent 0cba22ab0b
commit 022b4f034b
2 changed files with 69 additions and 0 deletions

23
srv/services.js Normal file
View File

@@ -0,0 +1,23 @@
const cds = require('@sap/cds')
class ProcessorService extends cds.ApplicationService {
/** Registering custom event handlers */
init() {
this.before("UPDATE", "Incidents", (req) => this.onUpdate(req));
this.before("CREATE", "Incidents", (req) => this.changeUrgencyDueToSubject(req.data));
return super.init();
}
changeUrgencyDueToSubject(data) {
let urgent = data.title?.match(/urgent/i)
if (urgent) data.urgency_code = 'H'
}
/** Custom Validation */
async onUpdate (req) {
let closed = await SELECT.one(1) .from (req.subject) .where `status.code = 'C'`
if (closed) req.reject `Can't modify a closed incident!`
}
}
module.exports = { ProcessorService }