Using lifecycles to create a slug

There is a fine documentation here that I am using:

However. My use case is that I want to use a combination of 4 different fields to create the slug and I do it like this:

module.exports = {

lifecycles: {
async beforeCreate(data) {
if (data.level && data.section && data.lesson && data.pageNo) {
data.slug = ${data.level}-${data.section}-${data.lesson}-${data.pageNo};
}
},
async beforeUpdate(params, data) {
if (data.level && data.section && data.lesson && data.pageNo) {
data.slug = ${data.level}-${data.section}-${data.lesson}-${data.pageNo};
}
},
},
};

This is working fine when I create but when I update, the update actually goes through but I still get an error message. The message goes away by refreshing the page and the data is OK but this is still annoying. Any ideas about what is wrong here?