trigger OnAfterModify()
var
RecEmailM: Codeunit "Email Message";
RecEmail: Codeunit Email;
Body: Text;
Msg: Label 'Hello <br><br>The Item No. is <strong>%1</strong>.<br><br>The Profit Percentage has changed, causing the Unit Price to be different from the Sales Price.<br><br>Regards,<br>BC System Message';
UserSetup: Record "User Setup";
UserIdVar: Text[100];
EmailCreated: Boolean;
begin
if (Rec."Profit %" <> xRec."Profit %") and (Rec."Unit Price" <> xRec."Unit Price") then begin
UserSetup.SETRANGE(ITNotify, TRUE);
if UserSetup.FINDSET THEN BEGIN
REPEAT
UserIdVar := FORMAT(UserSetup."User ID");
Body := StrSubstNo(Msg, Rec."No.");
RecEmailM.Create(UserSetup."E-Mail", 'Item - 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('Profit % has changed for item %1, causing the Unit Price to be different from the Sales Price.', rec."No.");
end;
end;