customization of sales invoice emailing

Three email fields have been created, and I want to take all those emails from all those three fields and add them to the "To" field. Anyone knows which event I should subscribe to or what needs to be done to include those emails?
195oj5mp55c0.png

6edhziiepqjp.png

Answers

  • ExploreExplore Member Posts: 14
    edited 2023-07-20
    To include emails from multiple fields into the "To" field, you can subscribe to the OnValidate trigger of the record containing the email fields. Within this trigger, you can concatenate the email addresses from the three fields and populate the "To" field.

    This is a sample code snippet you can change it.
    tableextension 50100 MyTableExt extends MyTable
    {
        trigger OnValidate()
        var
            Email1@field: Text[100];
            Email2@field: Text[100];
            Email3@field: Text[100];
            EmailTo@field: Text[100];
        begin
            EmailTo := '';
            if Email1 <> '' then
                EmailTo += Email1 + ';';
            if Email2 <> '' then
                EmailTo += Email2 + ';';
            if Email3 <> '' then
                EmailTo += Email3 + ';';
    
            Modify();
        end;
    }
    

    By subscribing to the OnValidate trigger and implementing the logic, the email addresses from the three fields will be combined and stored in the "To" field whenever the record is validated.
  • mustafaAlsoufimustafaAlsoufi Member Posts: 65
    @Explore
    dmcqd9k2qk5t.png

    I found a mail management codeunit #9520 I thought I could subscribe to one of their events(I might be wrong here) but I couldn't find any event where I could subscribe in order to assign those Email 2 and Email 3 to be in the CCList field instead of "To".

    Any suggestions?
  • ExploreExplore Member Posts: 14
    @mustafaAlsoufi
    OnValidate is a field trigger in Microsoft Dynamics NAV, and it is triggered when a value in a field is validated. Validation happens when you enter or modify the value in a field and then move the focus away from that field.

    It is commonly used to write custom code that should run after a value has been entered into a field and that value has been validated. You can use this trigger to check the validity of a value or to automatically populate other fields based on the value of the validated field.

    You can utilize the OnValidate trigger for the fields "Email", "Email 2" and "Email 3". Following this, the EmailTo variable ( that will be set as a SourceExpression in the "To" field on Page Designer) can be used to combine the email addresses from all three fields. The code snippet provided above serves as an example to help illustrate how to use onValidate trigger. If you're unfamiliar with the OnValidate trigger, it suggests that you might not have a development background. Therefore, you may find it beneficial to seek assistance from a developer within your organization.

Sign In or Register to comment.