Confirmation Dialog if field value is greater than certain amount

Hi,

I am looking to add a confirmation dialog box to my Sales Order Header page if a user inputs an unexpectedly large amount.

For example, if a user enters in a sales order with an amount of $50,000 I want a message to display in the RTC that asks the user if they would like to proceed.

I have written the below C/AL code which I’m sure is wrong. I would be very appreciative if someone could point me in the right direction. Thanks!

Amount - OnValidate()
IF (“Amount” > 50000) THEN
BEGIN
IF DIALOG.CONFIRM (Text002,TRUE) THEN
ERROR(‘Request Cancelled’);
END;

Using Dynamics NAV

Try this.

If the user chooses “Yes”, the process will continue.

IF (Amount > 50000) THEN
iF NOT CONFIRM(Text002) THEN
ERROR(‘Request Cancelled’);

Hi [mention:81eae18f857e4535929d7020ce75da2b:e9ed411860ed4f2ba0265705b8793d05]

Thank you for your reply.

Amount - OnValidate()
IF (Amount > 50000) THEN
IF NOT CONFIRM(Text002) THEN
ERROR(‘Request Cancelled’);

I have added the above code to my Sales Order Header page. I, unfortunately, don’t see any message appear when the user enters an amount greater than 50000

Is there additional code that I need to include?

Sales Header amount is flowfield are you trying to update values in flow field ?

Thanks, [mention:ce4688cb15b3402b992b48ef48d9f9a3:e9ed411860ed4f2ba0265705b8793d05]

I guess I should base this logic around a different field.

Perhaps the Line Amount of the Sales Lines page would be more appropriate?

Line Amount - OnValidate()
IF (“Line Amount” > 50000) THEN
IF NOT CONFIRM(Text002) THEN
ERROR(‘Request Cancelled’);

I’ve tried adding the above but I think I am still missing something. Basically just looking for a way to warn a user if a dollar amount > 50000 appears anywhere on a Sales Order.

Not recommend to hardcode amount ( 50000 ) in codes Create one setup in Sales & Receivables Setup

Create one codeunit and subscribe Sales Line OnAfterUpdateVATAmounts function


LOCAL [EventSubscriber] OnAfterUpdateVATAmounts(VAR SalesLine : Record "Sales Line")
IF SalesLine."Document Type" <> SalesLine."Document Type"::Order THEN 
  EXIT;
SalesReceivablesSetup.GET(); 

IF SalesReceivablesSetup."SO Warning Amount" = 0 THEN 
 EXIT;

SalesHeader.GET(SalesLine."Document Type",SalesLine."Document No.");
SalesHeader.CALCFIELDS(Amount);
IF (SalesHeader.Amount > SalesReceivablesSetup."SO Warning Amount") THEN
  IF NOT CONFIRM(Text001) THEN
    ERROR(Text002);

 

Hi [mention:ce4688cb15b3402b992b48ef48d9f9a3:e9ed411860ed4f2ba0265705b8793d05]

Appreciate you taking the time to provide code.

As you can tell I’m new to writing C/AL code.

The example code you provided. Is that what I should be inputting in a new Codeunit?

I see it should be added to a new Codeunit. I have set up the below. I need to figure out what settings to include for the SalesReceivablesSetup var

pastedimage1610126203701v2.png

You don’t need any settings, but you do need to declare the SalesReceivablesSetup variable pointing to the Sales & Receivables Setup record.

Thanks, [mention:61b2aa9ce72e429baa1ef43208ddbea4:e9ed411860ed4f2ba0265705b8793d05]

Here is where I’m currently at.

Codeunit C/AL

C/AL Locals

Function

pastedimage1610136630188v5.png

No errors when I save the Codeunit but I suspect I am still missing something.

Sales OrderWarning Amount is an integer field that I have added to table 311 Sales & Receivables Setup.

It has an initial value of 50000.

So far I have yet to produce a Confirm Dialog box in the RTC.

Appreciate the help from everyone

Have you tried to debug the code? Set a breakpoint on the publisher, and see if it doesn’t take you there. You can also check the list of event subscribers. I have experienced subscribers which have been failing because of “something”. And in that case the event subscriber list may tell you the reason.

Hi [mention:61b2aa9ce72e429baa1ef43208ddbea4:e9ed411860ed4f2ba0265705b8793d05]

I don’t see any errors when I look at the Event Subscribers. I have modified the code slightly so that it is an exact match of the suggestion provided by another user at the beginning of this thread. I need to better familiarize myself with the debugger. Hopefully, that will allow me to see what’s wrong. Thanks