Get record and check field value in one "IF" statement

_prt
Member Posts: 2
Is it safe to get record and check it's field's value in one "IF" statement? For example:
don't works and seems like Nav computes predicates from left to right
IF UserSetup.GET(USERID) AND (UserSetup."Main Menu ID" <> 0) THEN BEGIN //do something END;looks like this is works fine, but
IF (UserSetup."Main Menu ID" <> 0) AND UserSetup.GET(USERID) THEN BEGIN //do something END;
don't works and seems like Nav computes predicates from left to right
0
Comments
-
Hi,
Yes it will match the conditions starting from left to Right. First you will get the record and once the record is there then you can check the condition.
Thanks & Regards,
Saurav Dhyani
Do you Know this About NAV?
Connect - Twitter | Facebook | Google + | YouTube
Follow - Blog | Facebook Page | Google + Page0 -
First example looks ok and logical to me. But never used it because i found situations in where it didn't work.
Now all c/al code is converted to C# and it works as expected.0 -
While it evaluates from left to right, you should keep in mind it doesn't evaluate lazily.
For exampleIF FuncA AND FuncB THEN ...
will execute both functions even if FuncA returns false (e.g. a GET fails).
If you want lazy evaluation you can use 'IN' e.g.IF NOT (FALSE IN [FuncA,FuncB]) THEN ...
will perform a lazy AND operation.Thanks, Sam.
Microsoft Dynamics NAV | App Service Engineer | Comments are my own0 -
Thanks for your responses.mdPartnerNL wrote: »But never used it because i found situations in where it didn't work.0
-
samlieshout example demonstrates a situation in where left to right doesn't work;
IF FuncA AND FuncB THEN ...
but am not sure if this will not work in 2013 and higher??
0 -
mdPartnerNL wrote: »samlieshout example demonstrates a situation in where left to right doesn't work;
IF FuncA AND FuncB THEN ...
but am not sure if this will not work in 2013 and higher??
Yeah, this behaviour is the same in the recent releases.
Thanks, Sam.
Microsoft Dynamics NAV | App Service Engineer | Comments are my own0 -
would love to see the created C# code for this IF. As I understand, c# will run from left to right.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