Comparing two record variables

Belias
Member Posts: 2,998
I don't know if it's risky, or if it's a known habit of you guys, but sometimes i want to compare two record varibales and see if they're the same (i mean, through code). i also noticed that FORMAT function works with record variables.
Is there something wrong (or is there a better way to do it) in doing this?
Is there something wrong (or is there a better way to do it) in doing this?
IF FORMAT(mytablevariable1) = FORMAT(mytablevariable2) then //record variables are pointing exactly to the same record else //one or more field values are differenti think it is self documenting and smart, but i'm probably missing something...is it possible that nav does not have a function to compare two record variables? :-k
0
Answers
-
I've thought of several ways to code that type of request and I haven't seen anything like a single function that compares all values in the fields.
One thing I've seen done in the past is to use record ref variable and lookup the fields that are in the record and compare them. I think that's another way of comparing the records together....althought the format(recorda) = format(recordb) is probably just a good.0 -
It is good idea until the record is not too big to have more than 1000 chars when converted into text... ;-) Of course, using the recordref and fieldref to compare all fields is the clearest way.0
-
gah....I always forget about the size limits of the text datatype in NAV!!! Although I guess 1024 is better than the 250 or whatever it used to be!0
-
Yeah that only thing that has more room than a large text variable is a BLOB or BigText datatype and those wouldn't really be useful in this situation.
If only we could have access to the 2Gb string data type like in C#/VS.Net!0 -
Where did you get 1024 limitation? For Text variable 'no limits'
"If no length is specified for text variables, the length is unlimited."
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-object-specifications-limitations
FORMAT(Rec) limitation : If, when the system formats Value, the result is a value larger than the maximum length MAXSTRLEN method (Code, Text) of String, a run-time error occurs.
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-format-joker-integer-string-method
But MAXSTRLEN(TextVariable) = 2,147,483,647.
So, I compared:
if Format(Rec) <> Format(xRec) then
And it works on BC 16, OnPrem, AL extension.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