Using Option Var in IF Statement

toootooo Member Posts: 138
The first bit of the if works fine for blank and no but if the option is yes the second bit wont even generate a page for the report, any help appreciated!
IF "VAT Number" = 0 THEN BEGIN
  "Vat No X" := '';
  "Vat No" := '';
END ELSE BEGIN
  "Vat No X" := Text013;
  "Vat No" := Text014;
END;

Comments

  • SavatageSavatage Member Posts: 7,142
    which is the option?

    is VAT Number" = 0 an option field?
  • toootooo Member Posts: 138
    VAT Number variable has two options set in the table as no and yes
  • SavatageSavatage Member Posts: 7,142
    you you think your code is not working because text013 & text014 are not showing are you doing a modify of the table?

    you can test this
    IF "VAT Number" = 0 THEN BEGIN
    "Vat No X" := '';
    "Vat No" := '';
    END ELSE BEGIN
    "Vat No X" := Text013;
    message('%1',"Vat No X");
    "Vat No" := Text014;
    message('%1',"Vat No");
    END;

    If the valeus that pop up are correct you know you are simply not saving the new values.

    Oh is this a REPORT?????
  • toootooo Member Posts: 138
    Savatage wrote:
    you you think your code is not working because text013 & text014 are not showing are you doing a modify of the table?

    you can test this
    IF "VAT Number" = 0 THEN BEGIN
    "Vat No X" := '';
    "Vat No" := '';
    END ELSE BEGIN
    "Vat No X" := Text013;
    message('%1',"Vat No X");
    "Vat No" := Text014;
    message('%1',"Vat No");
    END;

    If the valeus that pop up are correct you know you are simply not saving the new values.
    Not even getting the message boxes up, Text013 and Text014 are constants and "Vat No" and "Vat No X" are global vars!?
  • SavatageSavatage Member Posts: 7,142
    oh it's a report??

    perhaps Vat No is NEVER 1 are you getting it from another table or is it part of your main dataitem?
  • kinekine Member Posts: 12,562
    tooo wrote:
    The first bit of the if works fine for blank and no but if the option is yes the second bit wont even generate a page for the report, any help appreciated!
    IF "VAT Number" = 0 THEN BEGIN
      "Vat No X" := '';
      "Vat No" := '';
    END ELSE BEGIN
      "Vat No X" := Text013;
      "Vat No" := Text014;
    END;
    

    Can you post the data type for each used variable?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • toootooo Member Posts: 138
    Please bare with me, im new to NAV development. I created a var on the sales header table called "Vat Number" and its type 'option' with no,yes set as the option string.
    Then on the report i have created two constants Text013 and Text014, i also created two global vars called "VAT No X" and "VAT No".

    In the Sales Invoice Header - OnPreDataItem() trigger i've added the above if statement!?

    Not sure if that helps?

    VAT Number - option
    VAT No - Text
    VAT No X - Text
  • SavatageSavatage Member Posts: 7,142
    1st you say you created a option variable on the "sales header".
    Is this a "real field" or just some variable on the form?

    2nd if you don't create the same "real field" in the "Sales invoice header" with the same number, it won't transfer over. therefore it doesn't exist.

    :-k :-k

    oh! 3rd if this field is just about being Yes or No - well that's exacty what a boolean type field is for.
  • toootooo Member Posts: 138
    Savatage wrote:
    1st you say you created a option variable on the "sales header".
    Is this a "real field" or just some variable on the form?

    2nd if you don't create the same "real field" in the "Sales invoice header" with the same number, it won't transfer over. therefore it doesn't exist.

    :-k :-k
    Sorry, ment to say the variable Vat Number is created in the Sales Invoice Header table, when i go to preview the report i can select the Vat Number option and select no or yes, when no is selected it runs as expected but when yes is selected in doesn't generate anything.
  • SavatageSavatage Member Posts: 7,142
    tooo wrote:
    when i go to preview the report i can select the Vat Number option and select no or yes

    Now I'm real confused. How do you select anything in a preview of a report?
    Do you mean you have a request form?

    FYI - boolean fields are made for true/false oryes/no, not options.
  • toootooo Member Posts: 138
    Savatage wrote:
    tooo wrote:
    when i go to preview the report i can select the Vat Number option and select no or yes

    Now I'm real confused. How do you select anything in a preview of a report?
    Do you mean you have a request form?

    FYI - boolean fields are made for true/false oryes/no, not options.
    Sorry about the confusion, yes i have a request form and i have the VAT Number option available on the left.
    I have changed it to be a boolean in the Sales invoice header table, i have found that when i leave the vat number field blank, no or yes it is passing no from the request form everytime?!

    Do i have to reference the Vat Number var in the sales invoice header somewhere else in the report or something?

    I appreciate all your help by the way!
  • kinekine Member Posts: 12,562
    Tooo, as you can see, there are some issues and bad design (using option variable as integer - check the documentation how the option type is used, using option for Yes/No instead boolean etc.). But regardless this, I think there must be some more code using the variable to do something in the report. Your part of the code cannot have direct effect to what is printed. There must be something more behind that...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    tooo wrote:
    Savatage wrote:
    tooo wrote:
    when i go to preview the report i can select the Vat Number option and select no or yes

    Now I'm real confused. How do you select anything in a preview of a report?
    Do you mean you have a request form?

    FYI - boolean fields are made for true/false oryes/no, not options.
    Sorry about the confusion, yes i have a request form and i have the VAT Number option available on the left.
    I have changed it to be a boolean in the Sales invoice header table, i have found that when i leave the vat number field blank, no or yes it is passing no from the request form everytime?!

    Do i have to reference the Vat Number var in the sales invoice header somewhere else in the report or something?

    I appreciate all your help by the way!

    1) How you are setting the value of the variable on the request page?
    2) Check if there is no local variable with same name...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • toootooo Member Posts: 138
    kine wrote:
    Tooo, as you can see, there are some issues and bad design (using option variable as integer - check the documentation how the option type is used, using option for Yes/No instead boolean etc.). But regardless this, I think there must be some more code using the variable to do something in the report. Your part of the code cannot have direct effect to what is printed. There must be something more behind that...

    I understand what your saying and i appreciate your comments, but i would have thought it easy enough to be able to populate a global var with a string based on a no/yes option on the request form which would affect the outcome of the report when its just a var thats assigned to a textbox!
  • kinekine Member Posts: 12,562
    Ok, than instead textbox use the check box. Check that there are no two variables with same name and it must work...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    where are you putting your code? Onaftergetrecord?

    FYI-Sometimes it really pays to post in detail what you want to to. else we have to keep posting to try an narrow down the goal.

    Now this field does it exist in the actual table? or did you create a variable in the report only?
    If it's in the actual table how did you switch it to a boolean so quickly.
    You would have had to clear any that ahad a value. So perhaps noting has a value therefore all = 0

    You know what i mean?
  • DenSterDenSter Member Posts: 8,305
    I am losing track of what the requirement is.... It looks as though you want to capture 'yes' or 'no', and you want to use an option type field for this purpose. You then use an integer type variable to capture that value, and you want to then translate that into a text variable that says 'yes' or 'no'?

    Did you know you can use a boolean type field/variable for this purpose? Did you know that by entering this boolean type as the source of a control, it will automatically be displayed as 'yes' or 'no'? C/AL will also be much easier, because a boolean, by its nature, evaluates to TRUE or FALSE, which are the two values possible in an IF statement.
  • DenSterDenSter Member Posts: 8,305
    Oh and on the request form you can simply put a checkbox for the user to check or uncheck. One click instead of two :mrgreen:
  • ReinhardReinhard Member Posts: 249
    Am I correct to suggest writing the code like this?

    [code]IF "VAT Number" = "VAT Number"::No THEN BEGIN
    "Vat No X" := '';
    "Vat No" := '';
    ...[code]

    Also I second what is being said: the piece of code you posted is correct. The reason that you are not getting the expected result is because "VAT Number" is not initialized correctly... somewhere
Sign In or Register to comment.