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.
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.
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.
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.
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. #-o
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. ](*,)
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?
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.
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.
Comments
RIS Plus, LLC
Why can't you just use :
Other wise you would have to go through each field individually.
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.
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.
But I guess it's not that important...
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
](*,) ](*,) ](*,)
That's what RecRef is for.
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. #-o
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. ](*,)
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?
Dave
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
{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.
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.
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com
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.