Confirmation Message!

nvermanverma Member Posts: 396
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

  • SavatageSavatage Member Posts: 7,142
    Sample 1 - Ondelete trigger on Purchase header table.....
    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!
  • nvermanverma Member Posts: 396
    sorry...i think im a little slow....but i dont get ur post.... :-k
  • ReinhardReinhard Member Posts: 249
    Savatage is giving some good examples.

    To give you specific feedback on your code.
    IF ("Reason for Termination Code" = 'Death') THEN
    BEGIN
    Answer := DIALOG.CONFIRM (Text002,TRUE);
    END
    ELSE
    EXIT;
    

    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:
    Answer := DIALOG.CONFIRM (Text002,TRUE);
    

    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)
    IF ("Reason for Termination Code" = 'DEATH') THEN
    BEGIN
      IF DIALOG.CONFIRM (Text002,TRUE) THEN
        ; //close all related jobs
      ELSE
        ERROR('');
    END;
    
  • SavatageSavatage Member Posts: 7,142
    I was trying to give some examples that if you can follow them will help you.

    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.
  • Mike_HWGMike_HWG Member Posts: 104
    Reinhard wrote:
    In the end your code will look something like this: (which won't fix the hardcoded issue I just mentioned btw)
    IF ("Reason for Termination Code" = 'DEATH') THEN
    BEGIN
      IF DIALOG.CONFIRM (Text002,TRUE) THEN
        ; //close all related jobs
      ELSE
        ERROR('');
    END;
    

    I would change things just a bit:
    IF "Reason for Termination" = "Reason for Termination::Death THEN BEGIN
      IF NOT DIALOG.CONFIRM(Text002,TRUE) THEN
        ERROR('Request Cancelled');
    END;
    
    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.
    Michael Hollinger
    Systems Analyst
    NAV 2009 R2 (6.00.34463)
  • nvermanverma Member Posts: 396
    So I have been able to make some progress with the code. This is the code now.


    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???
  • Mike_HWGMike_HWG Member Posts: 104
    edited 2011-12-06
    first off, please use the forum's 'code' button for your code, it makes it easier to read. :)

    On to the code. Read my comments.
    IF ("Reason for Termination Code" = '09') THEN BEGIN
      // Notice your semicolon here.  If the CONFIRM returns TRUE, then the code hits the semicolon and resolves, which then
      // continues to your EXIT statement.  
      //  If the CONFIRM returns FALSE, the code jumps out of the IF statement and continues to your EXIT statement.
      IF CONFIRM (Text002, FALSE) THEN
        //Need to put an action here
        ;  
      //Need to say ELSE here!
      EXIT;
    END ELSE IF (grecJob."Job Type" <> grecJob."Job Type"::Consumer) THEN BEGIN
      ERROR (Text003);
    END;
    



    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.
    Michael Hollinger
    Systems Analyst
    NAV 2009 R2 (6.00.34463)
  • kinekine Member Posts: 12,562
    // Notice your semicolon here.  If the CONFIRM returns TRUE, then the code hits the semicolon and jumps to where I've 
      // labeled 'Exit Point 1'.  If the CONFIRM returns FALSE, the code continues to your EXIT statement.
      IF CONFIRM (Text002, FALSE) THEN;  
      EXIT;
    
    The commend is not true... if the CONFIRM return TRUE, it will do nothing and will continue on next statement - EXIT. It means, if the reason is = '09' it will exit each time...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Mike_HWGMike_HWG Member Posts: 104
    :-# You are correct, I was focused on too many issues at once... fixing post.. fixed. :-$
    Michael Hollinger
    Systems Analyst
    NAV 2009 R2 (6.00.34463)
  • David_SingletonDavid_Singleton Member Posts: 5,479
    nverma wrote:
    sorry...i think im a little slow....but i dont get ur post.... :-k

    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.
    David Singleton
Sign In or Register to comment.