Skip to main content
Business Central forum
Unanswered

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

editSubscribe (4) ShareShare
ReportReport
Posted on by 83
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;}
  • Community member Profile Picture
    Community member 83 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;
  • Community member Profile Picture
    Community member 83 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

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,066 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,585 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans