ELSE IF question
josephdewey
Member Posts: 87
Hi Everybody,
I'm wondering why the following code doesn't work the way I want it to. I wanted it to figure out if the variable called OLStaging.ITEM_CODE is a Resource or an Item, but only if it's unblocked. And, I want it to run the ErrorAdd function whenever there's the item/resource doesn't exist, or if it exists but it's blocked.
Currently, if the Resource doesn't exist, then it doesn't run "ELSE IF Item.GET(OLStaging.ITEM_CODE) = TRUE THEN".
Thanks in advance for your help.
I'm wondering why the following code doesn't work the way I want it to. I wanted it to figure out if the variable called OLStaging.ITEM_CODE is a Resource or an Item, but only if it's unblocked. And, I want it to run the ErrorAdd function whenever there's the item/resource doesn't exist, or if it exists but it's blocked.
Currently, if the Resource doesn't exist, then it doesn't run "ELSE IF Item.GET(OLStaging.ITEM_CODE) = TRUE THEN".
Thanks in advance for your help.
VAR
OLStaging@1000000000 : Record 50040;
Item@1000000004 : Record 27;
Resource@1000000011 : Record 156;
ItemType@1000000014 : Text[30];
IF Resource.GET(OLStaging.ITEM_CODE) = TRUE THEN
IF Resource.Blocked = FALSE THEN
ItemType := 'Resource'
ELSE IF Item.GET(OLStaging.ITEM_CODE) = TRUE THEN
IF Item.Blocked = FALSE THEN
ItemType := 'Item'
ELSE
ErrorAdd('Item/Resource is blocked/doesn''t exist.');
Joseph Dewey
Microsoft Dynamics NAV User
Microsoft Dynamics NAV User
0
Comments
-
I found a workaround. This code works like I want it to. I still want to understand why my previous code doesn't work, though. I'd really like to understand NAV's C/SIDE structure for control statements, and I don't feel like I fully understand it.
IF (Resource.GET(OLStaging.ITEM_CODE) = TRUE) AND (Resource.Blocked = FALSE) THEN ItemType := 'Resource' ELSE IF (Item.GET(OLStaging.ITEM_CODE) = TRUE) AND (Item.Blocked = FALSE) THEN ItemType := 'Item' ELSE ErrorAdd('Item/Resource is blocked/doesn''t exist.');Joseph Dewey
Microsoft Dynamics NAV User0 -
the ELSE statement gets paired with the wrong IF. when using nested IF's like this, it's better to use BEGIN and END to specify where the ELSE goes.josephdewey wrote:I still want to understand why my previous code doesn't work, though.
Your first code, indented as the compiler should interpret it :IF Resource.GET(OLStaging.ITEM_CODE) = TRUE THEN IF Resource.Blocked = FALSE THEN ItemType := 'Resource' ELSE IF Item.GET(OLStaging.ITEM_CODE) = TRUE THEN IF Item.Blocked = FALSE THEN ItemType := 'Item' ELSE ErrorAdd('Item/Resource is blocked/doesn''t exist.');and the corrected version :IF Resource.GET(OLStaging.ITEM_CODE) = TRUE THEN BEGIN IF Resource.Blocked = FALSE THEN ItemType := 'Resource' END ELSE BEGIN IF Item.GET(OLStaging.ITEM_CODE) = TRUE THEN BEGIN IF Item.Blocked = FALSE THEN ItemType := 'Item' END ELSE ErrorAdd('Item/Resource is blocked/doesn''t exist.'); END ;0 -
This makes a lot of sense. Thanks a ton for your help!Joseph Dewey
Microsoft Dynamics NAV User0
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
- 322 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