Using Option Var in IF Statement

tooo
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;
0
Comments
-
which is the option?
is VAT Number" = 0 an option field?0 -
VAT Number variable has two options set in the table as no and yes0
-
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?????0 -
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.0 -
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?0 -
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?0 -
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 - Text0 -
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.0 -
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 :-k0 -
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.0 -
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.
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!0 -
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...0
-
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.
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...0 -
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!0 -
Ok, than instead textbox use the check box. Check that there are no two variables with same name and it must work...0
-
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?0 -
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.0 -
Oh and on the request form you can simply put a checkbox for the user to check or uncheck. One click instead of two0
-
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... somewhere0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions