Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Unanswered

Alert user when referenced table record on PO page has certain value

Posted on by 108
I am trying to extend the Purchase Order page so that when the customer table record referenced in the /Sell-to Customer No./ field of the Shipping and Payment section has a Payment Terms value of Prepayment, the user would be notified/alerted. I have attempted the below, but aside from not working, it is also preventing the user from accessing existing POs from the list (The record is not open error).
 
Ideally, this would be a persistent notification on the page starting from when the user first selects the customer address, and a skippable message()/pop-up alert when the /Send Email/ button is pressed. From my limited understanding, an event subscriber would be used for this...? Just don’t know which/how to identify and use it here.
 
Appreciate any help!
 
    trigger OnOpenPage();    var        POProformaWarning: Notification;        POProformaWarningLbl: Label 'Shipping to PROFORMA customer; DO NOT send PO before payment confirmation!';        CustRecRefVar: RecordRef;        CustVar: Record Customer;        PaymentTermsCodeVar: Code[20];    begin        if Rec./Sell-to Customer No./ <> '' then begin            CustVar.Get(Rec./Sell-to Customer No./);            CustRecRefVar.SetTable(CustVar);            PaymentTermsCodeVar := CustVar./Payment Terms Code/;            if PaymentTermsCodeVar = 'PREPAYMENT' then begin                POProformaWarning.MESSAGE(POProformaWarningLbl);                POProformaWarning.SCOPE := NotificationScope::LocalScope;                POProformaWarning.Send();            end;        end;    end;}
  • CU05061853-0 Profile Picture
    CU05061853-0 108 on at
    Alert user when referenced table record on PO page has certain value
    I tried another method shown below, inspired by this article by Yun Zhu; it is still not producing the desired outcome.
     
    Hope someone can point out where I'm going wrong?
     
     
        trigger OnOpenPage();
        var
            TableNumber: Integer;
            POProformaWarning: Notification;
            POProformaWarningLbl: Label 'Shipping to PROFORMA customer; DO NOT send PO before payment confirmation!';
            CustRecRef: RecordRef;
            CustFieldRef: FieldRef;
            PrepaymentCodeRef: Code[20];
        begin
            if (Rec."Sell-to Customer No." <> '') then begin
                TableNumber := Rec.Relation("Sell-to Customer No.");
                CustRecRef.Open(TableNumber);
                CustFieldRef := CustRecRef.Field(27);
                Evaluate(PrepaymentCodeRef, CustFieldRef.Value);
                if PrepaymentCodeRef = 'PREPAYMENT' then begin
                    POProformaWarning.MESSAGE(POProformaWarningLbl);
                    POProformaWarning.SCOPE := NotificationScope::LocalScope;
                    POProformaWarning.Send();
                end;
            end;
        end;
    }
     
    // same as above
     
        trigger OnInsertRecord(BelowxRec: Boolean): Boolean
        var
            TableNumber: Integer;
            POProformaWarning: Notification;
            POProformaWarningLbl: Label 'Shipping to PROFORMA customer; DO NOT send PO before payment confirmation!';
            CustRecRef: RecordRef;
            CustFieldRef: FieldRef;
            PrepaymentCodeRef: Code[20];
        begin
            if (Rec."Sell-to Customer No." <> '') then begin
                TableNumber := Rec.Relation("Sell-to Customer No.");
                CustRecRef.Open(TableNumber);
                CustFieldRef := CustRecRef.Field(27);
                Evaluate(PrepaymentCodeRef, CustFieldRef.Value);
                if PrepaymentCodeRef = 'PREPAYMENT' then begin
                    POProformaWarning.MESSAGE(POProformaWarningLbl);
                    POProformaWarning.SCOPE := NotificationScope::LocalScope;
                    POProformaWarning.Send();
                end;
            end;
        end;
  • CU05061853-0 Profile Picture
    CU05061853-0 108 on at
    Alert user when referenced table record on PO page has certain value
    I have to paste the code in a comment here, because when doing it in the original post, all quotation marks are automatically converted into //, even within the code snippet.
     
     
    trigger OnOpenPage();
        var
            POProformaWarning: Notification;
            POProformaWarningLbl: Label 'Shipping to PROFORMA customer; DO NOT send PO before payment confirmation!';
            CustRecRefVar: RecordRef;
            CustVar: Record Customer;
            PaymentTermsCodeVar: Code[20];
        begin
            if Rec."Sell-to Customer No." <> '' then begin
                CustVar.Get(Rec."Sell-to Customer No.");
                CustRecRefVar.SetTable(CustVar);
                PaymentTermsCodeVar := CustVar."Payment Terms Code";
                if PaymentTermsCodeVar = 'PREPAYMENT' then begin
                    POProformaWarning.MESSAGE(POProformaWarningLbl);
                    POProformaWarning.SCOPE := NotificationScope::LocalScope;
                    POProformaWarning.Send();
                end;
            end;
        end;
     
     
    trigger OnOpenPage();
        var
            POProformaWarning: Notification;
            POProformaWarningLbl: Label 'Shipping to PROFORMA customer; DO NOT send PO before payment confirmation!';
            CustRecRefVar: RecordRef;
            CustVar: Record Customer;
            PaymentTermsCodeVar: Code[20];
        begin
            if Rec."Sell-to Customer No." <> '' then begin
                CustVar.Get(Rec."Sell-to Customer No.");
                CustRecRefVar.SetTable(CustVar);
                PaymentTermsCodeVar := CustVar."Payment Terms Code";
                if PaymentTermsCodeVar = 'PREPAYMENT' then begin
                    POProformaWarning.MESSAGE(POProformaWarningLbl);
                    POProformaWarning.SCOPE := NotificationScope::LocalScope;
                    POProformaWarning.Send();
                end;
            end;
        end;
     

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans