function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RedSalesRedSales 

Use PRIORVALUE Function On Picklist Validation Rule

Hello,

 

I have a Picklist in which one of the fields is "Error". On a user changing form fields and choosing to choose a different picklist value I want a validation rule to check the previous value of the picklist field and to only allow certain values to be picked if previously at "Error".  I have tried the following.

 

OR(AND(PRIORVALUE(Request_Status__c)='Error' , Request_Status__c<>'Draft Request'),AND(PRIORVALUE(Request_Status__c)='Error' , Request_Status__c<>'Endorse'))

 

I receive an error as follows:

Error: Field Request_Status__c is a picklist field. Picklist fields are only supported in certain functions. Tell me more

 

The "Tell me More" link brings me to teh following article  https://avaya--c4rdev.cs12.my.salesforce.com/help/doc/user_ed.jsp?loc=help&target=tips_on_building_formulas.htm%23picklists_and_msps&section=Customizing

 

In which it states "

  • PRIORVALUE(Only in assignment rules, validation rules, workflow field updates, and workflow rules in which the trigger type is set to Every time a record is created or edited)"

I do want this to run though every time an edit occurs though so figured it should work.

 

Does anyone happen to know from looking at the above what I may be doing wrong and a way to get around this?

 

Thanks in advance.


Best Answer chosen by Admin (Salesforce Developers) 
klekle

Hi there,

 

Since you are using a picklist, you should use ISPICKVAL in your validation rule.  Also, you will need to rewrite your rule a little bit.  It looks like your rule is trying to say "If the previous value of Request_Status__c was Error, then the new value cannot be Draft or Endorse."  

 

If that is the case, your rule should look something like this:

 

OR(
AND(
ISPICKVAL(PRIORVALUE(Request_Status__c),"Error"), NOT(ISPICKVAL(Request_Status__c,"Draft Request"))
),

AND(
ISPICKVAL(PRIORVALUE(Request_Status__c),"Error"), NOT(ISPICKVAL(Request_Status__c,"Endorse")))

)

 

I hope this helps.

 

Kemi

All Answers

klekle

Hi there,

 

Since you are using a picklist, you should use ISPICKVAL in your validation rule.  Also, you will need to rewrite your rule a little bit.  It looks like your rule is trying to say "If the previous value of Request_Status__c was Error, then the new value cannot be Draft or Endorse."  

 

If that is the case, your rule should look something like this:

 

OR(
AND(
ISPICKVAL(PRIORVALUE(Request_Status__c),"Error"), NOT(ISPICKVAL(Request_Status__c,"Draft Request"))
),

AND(
ISPICKVAL(PRIORVALUE(Request_Status__c),"Error"), NOT(ISPICKVAL(Request_Status__c,"Endorse")))

)

 

I hope this helps.

 

Kemi

This was selected as the best answer
RedSalesRedSales

Thanks Kami for your help.  Much appreciated!

Tyler G 3Tyler G 3
Also Thank you! (6 years later :)
Matheus Matos 10Matheus Matos 10
Thank you!  8 years later 
sridhar bachu 20sridhar bachu 20
Thank You really. Helpful tip even after 8 years. :)
SerobaSeroba
Thank you. 8 years later :)
Ellie AfatmirniEllie Afatmirni
Thank you in 2021
Mayuri Upadhyaya 8Mayuri Upadhyaya 8
Thank you! 9 years later.
Christa DahlinghausChrista Dahlinghaus
Thank you!  10 years later!  This is exactly what I needed to know.  Just goes to show that Salesforce is timeless.
garov marrygarov marry

Bonefish Grill Happy Hour is a great way to get some delicious seafood without breaking the bank. Enjoy delicious seafood and low-priced drinks at this seafood restaurant’s happy hour every day.
Tomy BruceTomy Bruce
Thanks for sharing the great information. For more details visit: https://apksip.net/tiktok-18-plus-apk/
Vincent Charlet (FR)Vincent Charlet (FR)
2023 and still usefull, Thanks