web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

How to send email notification if Boolean is true

(1) ShareShare
ReportReport
Posted on by 289
Hi Guys,
I have created 2 fields on purchase order. Dock date & Stock date. & we have filled the date in both the fields, but if users changes the dates ,then it will send the email notification.
Is any way to do this.
 
Now I have requirement : My email functionality is works. I also received the email notification.
but I want ,I have created one Boolean field on user setup ,field name is : send email.so if this field value  is true ,then only email should be sent to users for which this is marked as true. 
 
I have the same question (0)
  • Gerardo Rentería García Profile Picture
    25,157 Most Valuable Professional on at
    Hi
    If I understand correctly, you should validate the existence of the user's configuration with the USERID variable and then ask for the boolean field that indicates whether or not it can send an email, similar to the following.
     
    Best regards
    Gerardo
  • Suggested answer
    tanya07 Profile Picture
    1,638 on at
    Hi,
    Yes exactly how Gerardo has mentioned , we  first check the user exists under the USERSETUP and then we can apply the logic you have wriiten.
    Best Regards,
    Tanya
  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at
    Hi, Just add some information, similar to the way.
     
    Hope this helps as well.
    Thanks.
    ZHU
  • Netjacker2097 Profile Picture
    286 on at
    Hi,
     
    i took what you did and made a sample of my own to help you aid in what you need to achieve. after you create the boolean field in the user setup that YUN ZHU mentioned, here is the code that you just need to check and change the Expected Receipt Date to your stock date. and then repeat for the other Dockdate. it should work as expected. i aso allow for the users with the Boolean tick is true for them to get the e-mail and also error checking if e-mail failed. Happy coding.
     
    tableextension 80023 PurchaseHeaderMK extends "Purchase Header"
    {
        trigger OnAfterModify()
        var
            RecEmailM: Codeunit "Email Message";
            RecEmail: Codeunit Email;
            Body: Text;
            Msg: Label 'Hello <br><br>The Purchase Order No. is <strong>%1</strong> from Vendor <strong>%2</strong>.<br><br>The Expected Receipt date is changed from <strong>%3</strong> to <strong>%4</strong>.';
            UserSetup: Record "User Setup";
            UserIdVar: Text[100];
            EmailCreated: Boolean;
        begin
     
            if (Rec."Expected Receipt Date" <> xRec."Expected Receipt Date") AND (xRec."Expected Receipt Date" <> 0D) then begin
     
                UserSetup.SETRANGE(PORNotify, TRUE);
                if UserSetup.FINDSET THEN BEGIN
                    REPEAT
     
                        UserIdVar := FORMAT(UserSetup."User ID");
                        Body := StrSubstNo(Msg, Rec."No.", rec."Buy-from Vendor Name", xRec."Expected Receipt Date", Rec."Expected Receipt Date");
     
                        RecEmailM.Create(UserSetup."E-Mail", 'Purchase Order - Email Notification', Body, true);
     
                        IF NOT RecEmail.Send(RecEmailM) THEN BEGIN
                            ERROR('Failed to send email to user: %1', UserIdVar);
                        END;
                    UNTIL UserSetup.NEXT = 0;
                END;
                Message('Expected Date changed from %1 to %2', xRec."Expected Receipt Date", rec."Expected Receipt Date");
            end;
        end;
    }
     
     
    Regards,
    M

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans