Compare xrec to rec

JohnCon
Member Posts: 55
Is it possible to compare all of xrec to rec rather than by field?
It tried if rec<>xrec then
but it wont let you do that.
It tried if rec<>xrec then
but it wont let you do that.
0
Comments
-
My guess is that if it doesn't work then it must not be possible to do it that way0
-
-
:?:
Why can't you just use :If format(xRec) <> format(rec) then message('The record was changed');
Other wise you would have to go through each field individually.David Singleton0 -
A way to do this is to create a global variable to temporarily store the "before" values (eg. global_var := Rec;) and then just compare, using the recordref and fieldref variable types, any differences between the global variable record to Rec. I've used this quite often and it works well.0
-
wonmo wrote:A way to do this is to create a global variable to temporarily store the "before" values (eg. global_var := Rec;) and then just compare, using the recordref and fieldref variable types, any differences between the global variable record to Rec. I've used this quite often and it works well.
I guess that would work also :-k , but it sounds quite complex . I have always done it by just the one line compare, but maybe I am just lazy and hate writing lots of lines of code. \:D/
By the way this sometimes does not work if you have very large records, but thats pretty rare, you would need a lot of populated fields to overflow.David Singleton0 -
Yes, David, you are definataly lazy.
Cool tip BTW. =D>0 -
Mark Brummel wrote:Yes, David, you are definataly lazy.
Cool tip BTW. =D>
Yeah Mark, I guess you are right, there are a ton of things I just do, and think "well surely everyone does it that way". But how do you remember them all.David Singleton0 -
Thanks I will try both options.0
-
It'd be nice if there was a function to loop through the fields on a table.
But I guess it's not that important...Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
JohnCon wrote:Thanks I will try both options.
](*,) ](*,) ](*,)deadlizard wrote:It'd be nice if there was a function to loop through the fields on a table.
But I guess it's not that important...David Singleton0 -
FOR i := 1 TO recref_Original.FIELDCOUNT DO BEGIN
IF recref_Original.FIELDINDEX(i).VALUE <> recref_New.FIELDINDEX(i).VALUE THEN BEGIN
{whatever action you want to do}
END;
END;
This is how to compare the values of each field between 2 tables.0 -
wonmo wrote:FOR i := 1 TO recref_Original.FIELDCOUNT DO BEGIN
IF recref_Original.FIELDINDEX(i).VALUE <> recref_New.FIELDINDEX(i).VALUE THEN BEGIN
{whatever action you want to do}
END;
END;
This is how to compare the values of each field between 2 tables.
OK, so it looks like Mark is right, I am just too lazy.
Of course me and my silly idea of writing just one line of code when just as easily you can write five. Sorry next time I will make the effort to write more code.
Not only that, but think of all the hardware suppliers that I am depriving of income by writing efficient code, rather than lots of lines that will sell more powerful hardware. Hey Mark, Dell must hate guys like us. #-oDavid Singleton0 -
True, I am having a discussion at this moment with a hosting company. They love to solve performance issues with more hardware, while I want to tune the database so we can use less hardware. ](*,)0 -
wonmo wrote:FOR i := 1 TO recref_Original.FIELDCOUNT DO BEGIN
IF recref_Original.FIELDINDEX(i).VALUE <> recref_New.FIELDINDEX(i).VALUE THEN BEGIN
{whatever action you want to do}
END;
END;
This is how to compare the values of each field between 2 tables.
I have not used RecRef much, so if this sounds dumb, don't worry.
So how would you assign say a modified Rec to recref_New ?
Remembering that both record have the same key (RecRef)!
We are not comparing Record1 to Record2, but Record1 to Record1 (Modified)
If you use a GET or SET would it not retreive the Original from the database?
DaveAnalyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com0 -
grec_Original := Rec;
{do something}
recref_Original.GETTABLE(grec_Original);
recref_New.GETTABLE(Rec);
You are now ready to compare field by field. I use this to log all changes done to a record. These changes (as text) get loaded into a BLOB field which can quickly be viewed with just a few lines of code and Notepad.0 -
Thanks:
I will try this, what I want is to allow users only to change a selection of fields, once an order reaches a particular status.
I.E. If the Purchase Header has been authorised then don't allow the Line Quantity to be changed, but the Qty. to Receive can be changed, this should work fine.Analyst Developer with over 17 years Navision, Contract Status - Busy
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com0 -
On the OnAfterGetRecord just add the code:
CurrForm."Line Quantity".EDITABLE({Purchase Header has been authorised});
And just repeat this line of code for any field you want to control edits on.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