I thought of describing the difference and usages of the
functions OriginalValue and PriorValue.
OriginalValue
This a useful property of a field class if you want to
revert the changes or compare with the previous value of the field.
&Value = RECORD.FIELD.OriginalValue;
This statement always returns the value of the field in the
database at that particular point of time. For the same reason, this property
will not work for derived records.
Say my field has value “FIRST” in the database and I change
it to “SECOND” and save it. Let us analyze the return value at various point of
time.
n
Component Loaded & value not yet changed.
&Value = RECORD.FIELD.OriginalValue; /*
Returns FIRST */
&Value = RECORD.FIELD.Value;/*
Returns FIRST */
n
After
changing the value to SECOND & before saving
&Value = RECORD.FIELD.OriginalValue; /*
Returns FIRST */
&Value = RECORD.FIELD.Value;/* Returns SECOND
*/
n
After saving the changes
&Value = RECORD.FIELD.OriginalValue; /*
Returns SECOND */
&Value = RECORD.FIELD.Value;/* Returns SECOND
*/
This function can be used to compare the value
with previous value and do some complex functionality. It is, if the change in
amount field is more than 10%, then trigger the workflow.
Another use case will be to revert the
changes back if some criteria is not met.
Well this is quite useful, but if the field
is a derived work record field, this property will not work at all.
PriorValue() is a lifesaver here.
PriorValue
Although it is similar to OriginalValue,
there is a notable difference. This always returns the value in the buffer just
before the change.
Let me explain it. Suppose the value in
data base is FIRST and after that I changes the value in the below pattern.
FIRST -> SECOND -> THIRD -> FOURTH
Now if I execute Original value, it will
return FIRST where as PriorValue will return THIRD (the value just before the
last change)
&Value = RECORD.FIELD.OriginalValue; /*
Returns FIRST */
&Value = RECORD.FIELD.Value;/*
Returns FOURTH*/
&Value = PriorValue(RECORD.FIELD); /*
Returns THIRD */
The advantage is that you can use this
function for a derived record also as the value is fetched from buffer and not
from database.
Note:-
There are two restrictions for usage of PriorValue to work correctly.
1.
It should be placed in FieldChange or FieldEdit events
2.
It should
be placed in the same record field event. For example if the record field is
JOURNAL.JOURNAL_ID. Then the code should
be placed in either JOURNAL.JOURNAL_ID.FieldEdit or JOURNAL.JOURNAL_ID.FieldChange.
In all other cases PriorValue() will return the current
value of field instead of prior value.
This information is invaluable. Where can I find out more?
ReplyDeleteCheck out my website; voucher codes
Hi, yup this paragraph is genuinely pleasant and I have learned lot
ReplyDeleteof things from it concerning blogging. thanks.
Check out my web page: sky 12 months
Yes it is really awesome
ReplyDelete