NAV Classic 2009 R2 - Case statements

jonesks
Member Posts: 29
Morning.
I am having to write case statements to pick out the country code and match it to the Country name. Tested it before I finished putting in the 80+ lines and It is just picking up the first case. It treats all customers as if it had GB. I inserted a test phraze in the first line - instead of blank I put "This is broken!" and when i ran the report it showed This is Broken on every address. Also I swapped the GB line for the SE line and ran it again to find out every address had Sweden on it.
I am obviously missing something but cannot see it. Can someone point me in the right direction?
Customer - OnAfterGetRecord()
CountryName :='Failure of address';
CASE "Country/Region Code" OF
("Country/Region Code"),'GB':CountryName :='';
("Country/Region Code"),'SE':CountryName :='SWEDEN';
("Country/Region Code"),'AE':CountryName :='United Arab Emirates';
("Country/Region Code"),'AR':CountryName :='Argentina';
ELSE
CountryName :='Not Working';
END
I am having to write case statements to pick out the country code and match it to the Country name. Tested it before I finished putting in the 80+ lines and It is just picking up the first case. It treats all customers as if it had GB. I inserted a test phraze in the first line - instead of blank I put "This is broken!" and when i ran the report it showed This is Broken on every address. Also I swapped the GB line for the SE line and ran it again to find out every address had Sweden on it.
I am obviously missing something but cannot see it. Can someone point me in the right direction?
Customer - OnAfterGetRecord()
CountryName :='Failure of address';
CASE "Country/Region Code" OF
("Country/Region Code"),'GB':CountryName :='';
("Country/Region Code"),'SE':CountryName :='SWEDEN';
("Country/Region Code"),'AE':CountryName :='United Arab Emirates';
("Country/Region Code"),'AR':CountryName :='Argentina';
ELSE
CountryName :='Not Working';
END
0
Best Answers
-
CASE "Country/Region Code" OF 'GB':CountryName :=''; 'SE':CountryName :='SWEDEN'; 'AE':CountryName :='United Arab Emirates'; 'AR':CountryName :='Argentina'; ELSE CountryName :='Not Working'; END;
You know that table 9 is used to retrieve country names according to country codes?6 -
Try
VAR Country : Record 9; ... IF Country.GET("Country/Region Code") THEN CountryName := Country.Name ELSE CountryName := 'Failure of address';
5 -
Just to help you understand your first code:
CASE a_variable OF something1a, something1b : do something 1 something2a, something2b : do something 2 ELSE do somethng 3 END
is equivalent toIF (a_variable = something1a) OR (a_variable = something1b) THEN do something 1 ELSE IF (a_variable = something2a) OR (a_variable = something2b) THEN do something 2 ELSE do something 3
What you have done is:CASE a_variable OF a_variable, 'GB': do something 1 ...
which logically translates toIF (a_variable = a_variable) OR (a_variable = 'GB') THEN do something 1 ELSE ...
Can you see now why it was always picking the first line?
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-036
Answers
-
Is this C/AL? It likely won't even compile! Check the syntax.0
-
Yes it is C/AL and I am very new to it! It is compiling though. I know it must be the syntax but I cannot for the life of me work out what I have done wrong!0
-
CASE "Country/Region Code" OF 'GB':CountryName :=''; 'SE':CountryName :='SWEDEN'; 'AE':CountryName :='United Arab Emirates'; 'AR':CountryName :='Argentina'; ELSE CountryName :='Not Working'; END;
You know that table 9 is used to retrieve country names according to country codes?6 -
Yes, just discovered that! When I said new to NAV - I mean two weeks! I realise what I did with the case statements now someone has pointed it out to me!
Now all I need to do is work out how to look up use table nine to give me the country name!
Thanks!
As Richard Branson said - if someone gives you a fantastic opportunity that you are not sure you can do, say yes and learn to do it later! (In my case thats on the job!)0 -
Ok - I know I can do this with about two lines of code - but I just cannot work it out! Any clues would be appreciated!
Thanks in advance!0 -
Try
VAR Country : Record 9; ... IF Country.GET("Country/Region Code") THEN CountryName := Country.Name ELSE CountryName := 'Failure of address';
5 -
Not sure what you want there. You asked a question and you marked two replies as the answer. If there is something else you need help with, the best thing to do is create a new topic.0
-
Sorry for the confusion - The first answer works - it solves the problem I was having with the syntax I then realised that there must be an easy way to do it and the second answer is the easy way to do what I was wanting so both answers are very good and both work!0
-
Just to help you understand your first code:
CASE a_variable OF something1a, something1b : do something 1 something2a, something2b : do something 2 ELSE do somethng 3 END
is equivalent toIF (a_variable = something1a) OR (a_variable = something1b) THEN do something 1 ELSE IF (a_variable = something2a) OR (a_variable = something2b) THEN do something 2 ELSE do something 3
What you have done is:CASE a_variable OF a_variable, 'GB': do something 1 ...
which logically translates toIF (a_variable = a_variable) OR (a_variable = 'GB') THEN do something 1 ELSE ...
Can you see now why it was always picking the first line?
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-036 -
Yes - I had gone mentally blind! First time I have worked in C/AL and haven't done any coding for ten years. As soon as I saw AK's answer I kicked myself!0
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