Announcement

Collapse
No announcement yet.

Advanced pack - workflow email

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advanced pack - workflow email

    How can i extend advanced pack workflow to add option to send email to a value from record field? I have custom entity with field email and when i add a new record i want to send an email to the email entered in that field. Or other way to do it - on a new record added i would like to create new customer (this is possible workflow and i can do it). Then i would like to send an email to this newly created customer.

    Dynamic "sent to" field would be a really nice option.

    Regards, Egi

  • #2
    I have managed to add dynamic mail option to Workflow action "Send Email" to dropdown "To" and "Reply-to" option list.

    When you create action send email, dropdown to and reply-to will be filled with additional options from selected entity. In dropdown you will see Entity name: field name as additional option.
    When you select this option and workflow is executed, code will read field value, check if it is a valid email and send it to that email address.

    Code to extend functionality:

    FILE: client/modules/advanced/src/views/workflow/action-modals/send-email.js

    Add this code:
    Code:
    [B]html += this.getEntityOptions(value); [/B]
    before code (line 210 and 239):
    Code:
    [I]html += this.getLinkOptions(value, false, true);[/I]
    Add this code:
    Code:
    getEntityOptions: function (value, onlyUser, noMultiple) {
        var html = '';
        var fieldDefs = this.getMetadata().get('entityDefs.' + this.entityType + '.fields') || {};
        Object.keys(fieldDefs).forEach(function (item) {
            if (~['varchar','email'].indexOf(this.getMetadata().get(['entityDefs', this.entityType, 'fields', item, 'type'])) &&
                !(this.getMetadata().get(['entityDefs', this.entityType, 'fields', item, 'disabled']))
            ) {
                var label = this.translate(item, 'fields', this.entityType);
                var labelEntity = this.translate(this.entityType, 'scopeNames');
                html += '<option value="field:' + item + '" ' + (item === value ? 'selected' : '') + '>' + labelEntity + ': ' + label + '</option>';
            }
        }, this);
        return html;
    },
    Before code (line 244):
    getLinkOptions: function (value, onlyUser, noMultiple) { ....


    FILE: application/Espo/Modules/Advanced/Core/Workflow/Actions/SendEmail.php (you can also override this class in custom folder)

    Put this code:
    PHP Code:
    if (strpos($fieldValue'field:') !== false) {
        
    $fieldId substr($fieldValue6);
        
    $email $entity->get($fieldId);
        if(
    filter_var($emailFILTER_VALIDATE_EMAIL)) {
            
    $returnData = array(
                
    'email' => $email,
                
    'type' => 'specifiedEmailAddress',
            );
        }
        break;

    After this code (line 180):
    PHP Code:
    default:
        
    $entity $this->getEntity(); 

    Next improvement would be to add fields from related entities.

    Regards, Egi

    Comment

    Working...
    X