Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Change workflow email notification template or from address based on payload path in a multi tenant architecture

Avatar

Level 1

Dear community,

 

I have a requirement where the platform uses multi tenant model and each tenant prefers a different email template and from adress , be used for notifications originating from workflows when initiated against their own content. Example /content/abc site contents when put through workflow process, the email address to use will be ABCWorkflowAdmin@mycompany.com and similarly /content/xyz will use XYZWorkflowAdmin@mycomany.com , and in addition based on different scenarios, they also prefer different email templates be used instead of using the raw default templates provided out of the box. I see there are many posts suggesting creation of a custom step with the entire custom behavior. Though the approach is usable to certain extent, will it not hinder the actual workflow definition. In reality the sending email part is just a way of notifying there is a task due for their review, and workflow itself shouldn't be altered to include this step. And in another perspective, for some reason if a step fails, and we opt to retry the operation of use the go back step, this step may be visible in their list of previous workflow steps which we definitely don't want users/participants of the workflow to see. Please do share your thoughts on the best course of action in use cases like these. I did go through the internal code by decompiling the java code of different bundles and there are way too many dependencies which we don't feel comfortable bringing into our custom code and maintain it. Wondering if there is an easy way to inject a new OSGI service or a an interface implementation with higher priority/ranking or precedence so the custom code we have will be used specifically in those use cases. In the event you also feel we need such a feature and if there are no alternatives at this time, please respond back to this post so the admins can consider this to be a feature request for future releases.

 

Thanks in advance,

Mahidhar Ch

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

3 Replies

Avatar

Level 4

Hi @mahi765183,

 

You can find OOTB logic in the com.day.cq.workflow.impl.email.EMailNotificationService. Unfortunately, there is no room to implement any additional factory or builder that can pre-process email creation.

 

However, there is another trade-off in your case: you can disable all notifications in the default EMailNotificationService via OSGi config (notify.onabort, notify.oncomplete, notify.oncontainercomplete, notify.useronly). Therefore, to implement your logic you will need to create your own implementation of EventHandler like in the com.day.cq.workflow.impl.email.EMailNotificationService, but with dynamic logic around emailFrom and templatePath properties.

Avatar

Level 1

Thank you so much for the inputs. Yes I did consider exploring the alternative before posting the question here .. And prefer not to redo the entire thing that existing service is already doing .Even if I wanted to consider writing another service with a better ranking to override the email id, without payload its not possible. I wish there is a better way to customize this. Once again appreciate your time and analysis !

Avatar

Level 4

I faced similar problem in my experience and I had to implement custom logic that I described above. Of course I had to cover all scenarios that are in OOTB logic.

Unfortunately, I didn't find any place to extend this logic in more fancy way.

If you find it, please share it with us.