JointLantic

How to use OriginalValue and PriorValue in peoplecode function

How to use OriginalValue and PriorValue in peoplecode function

How to use OriginalValue and PriorValue in peoplecode function for compare field value.

OriginalValue

OriginalValue function use syntax recordname.fieldname.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.

&FieldValue = recordname.fieldname.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 field value at various point of time.

Step 1.  Component Loaded & value not yet changed.

&Value = recordname.fieldname.OriginalValue; /* Returns first value */

&Value = recordname.fieldname.Value;/* Returns first value */

Step 2.  After  changing the value to second & before saving

&Value = recordname.fieldname.OriginalValue; /* Returns first value */

&Value = recordname.fieldnameValue;/* Returns second value*/

Step 3. After saving the changes

&Value = recordname.fieldname.OriginalValue; /* Returns second value*/

&Value = recordname.fieldname.Value;/* Returns second value */

This function can be used to compare the field value with previous field 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

PriorValue function use syntax PriorValue( recordname.fieldname)

Use the PriorValue function in FieldEdit and FieldChange: Returns value in field before field was changed by user. If used in other PeopleCode programs, returns current value. 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.

ref : http://www.peoplesoftjournal.com/2013/01/originalvalue-and-priorvalue.html

Exit mobile version