Email Template- how to programmatically set report entity in email template

Hi all,
Please I am getting this error message when I try to email using an email template. I have a template that is designed to send emails and attach reports with a pdf output.
The error is below:

Required report parameter “entity” not found

I know what is causing the error but I don’t know how to resolve it programmatically. There is not enough documentation on how to attach a report in an email template programmatically.

See my come below:

	public void emailRFQ(QuotationRequest quoteReq)  {
        //set the tenant email smtp details
        getMailPropertiesByTenant(quoteReq.getTenant());
        String subject = messages.formatMessage(getClass(),"rfqCreation.subject",quoteReq.getRfqNo());
        String orgName = tenantService.getTenant(quoteReq.getTenant()).getName();
		
        try {

            emailTemplates.buildFromTemplate(RFQ_CREATION_TEMPLATE_CODE)
                    .setFrom(tenantService.getTenant(quoteReq.getTenant()).getSenderEmail())
                    .setTo(quoteReq.getCustomer().getSalesPerson().getEmail())
                    .setSubject(subject)
                    .setBodyParameter("quotationRequest", quoteReq)
                    .setBodyParameter("bpCode", quoteReq.getCustomerCode())
                    .setBodyParameter("bpName", quoteReq.getCustomer().getBpName())
                    .setBodyParameter("salesperson", quoteReq.getCustomer().getSalesPerson().getName())
                    .setBodyParameter("orgName",orgName)
                    .sendEmailAsync();

        }
        catch (TemplateNotFoundException | ReportParameterTypeChangedException e) {
            log.error("Error on notifying rfq creation: {}",e.getMessage());
        }
    }

See the screenshot of the email template and the attached report

image

I don’t know how to set the entity programmatically. The entity is the quoteReq parameter of the method but I don’t know how to set it programmatically in the email template

Thank you

Hello,

You can call the generateEmail(..) method, which receives a Map<?,?> with all parameters and generates an EmailInfo object.

    @Subscribe("usersTable.send")
    public void onUsersTableSend(final Action.ActionPerformedEvent event) throws TemplateNotFoundException, ReportParameterTypeChangedException, EmailException {
        User singleSelected = usersTable.getSingleSelected();

        if (singleSelected == null) {
            return;
        }

        Map<String, Object> params = Map.of(
                "entity", singleSelected, //Entity for the report
                "emailParam", "Text" //Parameter for the email template
        );

        EmailInfo emailInfo = emailTemplates.generateEmail(TEST_TEMPLATE_CODE, params);
        emailInfo.setAddresses("admin@haulmont.com");

        emailer.sendEmail(emailInfo);
    }

Regards,
Nikita