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) THENBEGINIF DIALOG.CONFIRM (Text002,TRUE) THENERROR('Request Cancelled');END;
Using Dynamics NAV
If the user chooses "Yes", the process will continue.
IF (Amount > 50000) THEN iF NOT CONFIRM(Text002) THEN ERROR('Request Cancelled');
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 ?
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) THENIF NOT CONFIRM(Text002) THENERROR('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
IF SalesReceivablesSetup."SO Warning Amount" = 0 THEN
SalesHeader.GET(SalesLine."Document Type",SalesLine."Document No.");
IF (SalesHeader.Amount > SalesReceivablesSetup."SO Warning Amount") THEN
IF NOT CONFIRM(Text001) THEN
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
You don't need any settings, but you do need to declare the SalesReceivablesSetup variable pointing to the Sales & Receivables Setup record.
Thanks, Erik P. Ernst
Here is where I'm currently at.
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 Erik P. Ernst
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