A simple If then else statement - or so I thought

JonAJonA Member Posts: 23
Hi,

I tried to add a simple IF statement to our sales invoice report, the intention is to display different text if payment method code is DD (Direct Debit).
I tried entering the code below but I get a syntax error, I have declared the variable mytext as text (50).
IF "Sales Invoice Header"."Payment Method Code" = 'DD' THEN
mytext := 'Direct Debit will be collected on'
ELSE
mytext := 'Payment is due on'
END;

I really don't know what I'm doing! I'm trying to experiment on a backup copy - any help greatly appreciated, thanks. :?:

Comments

  • JonAJonA Member Posts: 23
    Sorry should have specified Navision 5.0
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    It should be
    IF "Sales Invoice Header"."Payment Method Code" = 'DD' THEN
    mytext := 'Direct Debit will be collected on'
    ELSE
    mytext := 'Payment is due on';
    
  • DenSterDenSter Member Posts: 8,307
    To elaborate a little - you have an END without a BEGIN. Mohana's suggestion is to eliminate the END because there is no BEGIN. Another suggestion (which I personally prefer) is to always use BEGIN and END in IF statements, like this:
    IF "Sales Invoice Header"."Payment Method Code" = 'DD' THEN BEGIN
      mytext := 'Direct Debit will be collected on';
    END ELSE BEGIN
      mytext := 'Payment is due on';
    END;
    
    Note that without the BEGIN and END, the one statement in the TRUE part of the IF statement does NOT have a semicolon, because the TRUE and FALSE part of the IF are considered part of one statement.
  • JonAJonA Member Posts: 23
    Thank you guys, Mohana and Denster - works perfectly either way, I appreciate your help.
Sign In or Register to comment.