+ Start a Discussion
RadDude89RadDude89 

Using priorvalue on validation rule

Hi,

I'm trying to create a validation rule that looks at a picklist field and return an error if the value has been changed after the record is approved.

The field contains 4 selections: 14, 30, 45 and 60.

What I'm trying to achieve is a validation rule that if a user (originally created the record with 14 as the selection) was to change it to 30, then they would get an error message "you can not change after approval".

When I try using the priorvalue, it says that this function can not be used in this type of formula.
I tried changing it to use TEXT values i.e.
(TEXT(Payment_Date__c) != TEXT(PRIORVALUE(Payment_Date__c)))

However this doesn't return the error message even I'm able to save the validation rule.

Does anyone know how to achieve using priorvalue for picklists? What is the best method for this?

Best Answer chosen by RadDude89
Pankaj_GanwaniPankaj_Ganwani
Instead of using priorvalue, you can use ischanged() function to detect the change on picklist.
ISCHANGED(fieldname__c) && status__c = 'Approved'

 

All Answers

Pankaj_GanwaniPankaj_Ganwani
Instead of using priorvalue, you can use ischanged() function to detect the change on picklist.
ISCHANGED(fieldname__c) && status__c = 'Approved'

 
This was selected as the best answer
mritzimritzi
PRIORVALUE( FieldApiName)  = '14' && NOT( ISNEW())

This will flag error message only for updated record, where previous value was 14.

Mark this as Best Answer, if this solves your problem.
RadDude89RadDude89
Actually sorry I got the ISCHANGED function working - thanks for your help!
mritzimritzi
@pankaj,
Correct if i am wrong, but my understanding of:
ISCHANGED(fieldname__c) && status__c = 'Approved'
is as follows:

ISCHANGED(fieldname__c) ->  Checks if the field has been updates, return true if changed/updated.
fieldname__c (status__c) = 'Approved' -> Checks if the field's current value is 'Approved' or 14 (as per Question detail)

That means error will be flagged if the record is updated and current value of fieldname__c is 14/Approved.

But the question description says that error message should be flagged if previous value of fieldname__c was 14/Approved and current value is something else (anything except 14/Approved).
Pankaj_GanwaniPankaj_Ganwani
As per the problem statement, the error message should be displayed if user tries to update the picklist value when record is 'Approved'. He has mentioned '14' as picklist value for giving us an example of the scenario so that we can get better understanding of his problem.