I know this is a very basic thing, but I am having a hard time wrapping my head around it.
This is what I have to do: When "Reason of Termination field on job card is set to "Death", it should display a confirmation message to proceed with closing the associated consumer and all related jobs. If the end user clicks "NO". then stop processing. Otherwise continue.
First of all I am not really sure, which trigger I should put the code in so it executes it when the reason of termination is death (my guess is OnValidate).
I know that the syntax of confirm is : Dialog.CONFIRM(String [, Default] [, Value1] ,...). I am not really sure, How to use it??
This is the code I have thus far:
Text002 (global variable) := The consumer card and all jobs linked to the consumer will be closed/blocked.
IF ("Reason for Termination Code" = 'Death') THEN
BEGIN
Answer := DIALOG.CONFIRM (Text002,TRUE);
END
ELSE
EXIT;
When I run the Job Card and the reason of Termination code is set to death, nothing happens.
Comments
OnDelete()
PurchSetup.GET;
IF PurchSetup."Double Delete Warning" THEN BEGIN
IF NOT CONFIRM('ARE YOU REALLY SURE YOU WANT TO DELETE THIS ORDER?',FALSE)
THEN ERROR('');
END;
Sample 2 - On customer table to ask about inv copies!....
Invoice Copies - OnValidate()
IF CONFIRM('Are You Absolutely Sure You Want Multiple Copies Of An Invoice For Customer %1',TRUE,"No.")
THEN EXIT
ELSE "Invoice Copies" := 0;
Sample 3 - On customer table blocked field.
Blocked - OnValidate()
IF NOT Blocked THEN BEGIN
IF CONFIRM('Customer %1 is blocked for a reason. Are you sure you want to unblock %2?',FALSE,"No.",Name)
THEN MESSAGE('Customer Unblocked!')
ELSE Blocked := TRUE;
END;
Sample 4 - on item table - ask about changing the description
IF (Rec.Description <> xRec.Description) THEN
IF NOT CONFIRM('Do you want to change the value from "%1" to "%2" in field "%3"?',FALSE,
xRec.Description,Rec.Description,FIELDCAPTION(Description)) THEN
ERROR('Press ESC to exit the field');
END;
Sample 5 - item table on entry of upc case
Case UPC/EAN Number - OnValidate()
IF InvtSetup."Validate UPC Length" THEN BEGIN
IF NOT (STRLEN("Case UPC/EAN Number") IN [0,12]) THEN
IF NOT CONFIRM(
'%1 is normally 12 digit, use this number anyway?',FALSE,
FIELDNAME("Case UPC/EAN Number"))
THEN
ERROR('Nothing Changed.');
END;
Good Luck!
http://www.BiloBeauty.com
http://www.autismspeaks.org
To give you specific feedback on your code.
First of all, try commenting out the IF "Reason for Death" condition which might be causing your problem, and see if the confirmation box pops up.
So the onValidate trigger would look like this:
Second, there are a couple of potential problems with your condition.
If Reason for Termination Code is a Code field, it will always be uppercase. In which case it will never equals Death. Only DEATH. So that might be your problem, or your problem might be something else, like the onValidate trigger isn't getting called, for example.
Also you are using a hard-coded "magical constant" ie if tomorrow you change the termination code to DECEASED your application will no longer work correctly.
In the end your code will look something like this: (which won't fix the hardcoded issue I just mentioned btw)
Question:: is Reason for termination and option field, then you have to do it a bit differently then just =
if "Reason for Termination Code" = "Reason for Termination Code"::Death then begin.....
play around with it.
http://www.BiloBeauty.com
http://www.autismspeaks.org
I would change things just a bit:
Notice what I did with the IF NOT statement. Also, I would change the "Reason For Termination Code" to an Option field (notice I renamed the field to follow best practices since it is no longer a code field).
By using "Reason for Termination::'Death', you help to eliminate the hardcoded value. The system instead translates the value to the proper option.
Systems Analyst
NAV 2009 R2 (6.00.34463)
IF ("Reason for Termination Code" = '09') THEN
BEGIN
IF CONFIRM (Text002, FALSE) THEN;
EXIT;
END
ELSE
IF (grecJob."Job Type" <> grecJob."Job Type"::Consumer) THEN
BEGIN
ERROR (Text003);
END;
So Now it goes into the loop checks if the reason of terminiation is = 09 (which is deaths) and the confirmation dialog box pops up. But it doesnt do anything. Even if i click yes or no...the dialog box disappears.
What i want it to do is, when i click NO, I want to exit the dialog box and when i click yes..i want it to check if the job type is = to consumer (but it doesnt do that either way).
Any ideas or suggestions???
On to the code. Read my comments.
In situations like this, you can use the debugger, or try putting in a statement for MESSAGE('got here') in various places in case the debugger isn't giving you the visibility you need.
Systems Analyst
NAV 2009 R2 (6.00.34463)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Systems Analyst
NAV 2009 R2 (6.00.34463)
Harry's post was very clear and contains the information that you need. If you don't understand then you need to get back to Navision basics. Without a basic understanding of how Navision works, and how to use C/AL you can not expect to write code that will work.