Skip to Content
Menu
This question has been flagged

When you share (button) a survey, you get an email template where you can add a recipient (eg customer).


Can anyone guide me creating a server action that does this within a marketing automation activity? I think, the server action has to do two thints:

1. Set the recipient

2. Send the email


Thanks for support

Avatar
Discard
Best Answer

To send a survey invitation email automatically within a Marketing Automation Activity in Odoo, you can use a Server Action to generate and send the survey email. Below is a step-by-step guide on how to achieve this:

1. Prerequisites

  • Ensure the Surveys module is installed.
  • Create or have an existing survey ready to send.
  • Make sure you have a working email setup configured in Settings > Email.

2. Create an Email Template

  1. Navigate to Email Templates:
    • Go to Settings > Technical > Email > Templates.
    • Click Create to design a new email template for your survey.
  2. Set the Template Details:
    • Name: Enter a meaningful name (e.g., "Survey Invitation").
    • Model: Choose the relevant model (e.g., "Contact" or "Survey").
    • Body: Design the email body and include the survey link. You can use placeholders for dynamic fields:
      Hello ${object.name},
      
      We invite you to participate in our survey. Please click the link below:
      
      ${object.response_url}
      
      Thank you!
      
    • Save the template.

3. Create the Server Action

  1. Navigate to Server Actions:
    • Go to Settings > Technical > Automation > Server Actions.
    • Click Create to define a new server action.
  2. Configure the Action:
    • Name: Enter a descriptive name (e.g., "Send Survey Invitation").
    • Model: Select the model where the server action will run (e.g., "Survey", "Contact", or "Lead").
    • Action To Do: Choose Execute Python Code.
  3. Add Python Code: Use the following Python script to send the survey email dynamically:
    template_id = env.ref('your_module_name.email_template_survey_invitation')
    if template_id:
        for record in records:
            template_id.send_mail(record.id, force_send=True)
    
    • Replace your_module_name.email_template_survey_invitation with the technical name of the email template created in Step 2.

4. Add the Server Action to Marketing Automation

  1. Create or Edit a Campaign:
    • Go to Marketing > Automation.
    • Create a new campaign or open an existing one.
  2. Add an Activity:
    • Add an activity that triggers the server action. For example:
      • Trigger Type: Email Sent, Record Creation, or Specific Time Delay.
      • Action: Select the server action created in Step 3.

5. Test the Setup

  • Trigger the marketing campaign or activity.
  • Verify that:
    • The email is sent to the recipient.
    • The survey link is included and functional.

6. Additional Notes

  • Dynamic Survey Links: If the survey is linked to a specific recipient, ensure the email template dynamically includes their response link using the response_url field.
  • Error Handling: Include logging in the server action to capture any errors:
    try:
        template_id.send_mail(record.id, force_send=True)
    except Exception as e:
        _logger.error("Error sending survey invitation: %s", e)
    

Outcome

When the marketing automation activity triggers the server action, it will dynamically send the email to the recipients with the survey link. This allows you to automate survey invitations seamlessly.

Let me know if you need further assistance!

Avatar
Discard
Best Answer

Yes the solution in odoo 16 (17 and 18), you can create a email template in the model you need example Sales Order.
With Qweb edit the template and write: you can sustitute the object.x_studio_many2one_field_SLIMM.get_start_url() with link you have of survey.



    <a t-att-href="object.x_studio_many2one_field_SLIMM.get_start_url()" style="box-sizing:border-box;background-color: #875A7B; padding: 8px 16px; text-decoration: none; color: #fff; border-radius: 5px; font-size:13px;">

        Survey

    </a>

And go to Technical -> Automated Actions, you push in new and action to do send by email.

Avatar
Discard
Best Answer

Hi, have you found a solution for that?

Best regards, michael 

Avatar
Discard
Best Answer

Hello, 

I'm also looking to do this. 

Have you found the solution?

Thanks

Avatar
Discard

I posted one of possible solution!

Related Posts Replies Views Activity
1
Mar 24
1024
1
Jun 22
4549
1
Feb 25
384
3
Jun 23
8841
14
Aug 20
7096