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
John ClevelandJohn Cleveland 

Validation to only allow user to change status if current status is A and only allow to change to status B

I'm usually pretty great at writing validation rules but guess this Monday isn't off to a great start. I'm trying to write one with the below criteria and I'm not getting anywhere. 

Any help would be greatly appreciated! 

1) All profiles except 2.
2) Certain Record Types
3) Status__c can only be changed if current status is "Status A". 
4) Status__c can only be changed to "Status B". 
 
AND( 
$Profile.Name <> 'Custom A', 
$Profile.Name <> 'System Administrator', 
CONTAINS(RecordType.Name , "Custom"), 
OR( 
NOT(ISPICKVAL(PRIORVALUE(Status__c), "Status A")), 
AND( 
ISCHANGED(Status__c), 
ISPICKVAL(PRIORVALUE(Status__c), "Status A"), 
NOT(ISPICKVAL(Status__c, "Status B")) 
) 
) 
)

 
Maharajan CMaharajan C
Hi John,

Put the OR Condtion in Profiles also.

AND( OR($Profile.Name <> 'Custom A', $Profile.Name <> 'System Administrator'), CONTAINS(RecordType.Name , "Custom"), OR( NOT(ISPICKVAL(PRIORVALUE(Status__c), "Status A")), AND( ISCHANGED(Status__c), ISPICKVAL(PRIORVALUE(Status__c), "Status A"), NOT(ISPICKVAL(Status__c, "Status B")) ) ) )

Can you please Let me know if it works or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks,
​Raj
July 18,
John ClevelandJohn Cleveland
It's using profile name not equal to, so an OR around those will not work.  I tried it just to make sure it wasn't part of my moment and it failed and wouldn't allow me to update.
John ClevelandJohn Cleveland
This seems to be working with the exception of when I change a record from "Status A" to "Status B". It is not letting the user change the status to anything after its created which it has a null value after creation which is good, since I only want the user to be able to change the status when the current status of the record is "Status A" and I only want them to be able to change the status to "Status B".  Any ideas? 
 
AND( 
$Profile.Name <> 'Custom', 
$Profile.Name <> 'System Administrator', 
CONTAINS(RecordType.Name , "Custom"), 
NOT(ISNEW()), 
OR( 
NOT(ISPICKVAL(PRIORVALUE(Status__c), "Status A")) 
, 
AND( 
ISCHANGED(Status__c), 
ISPICKVAL(PRIORVALUE(Status__c), "Status A"), 
NOT(ISPICKVAL(Status__c, "Status B")) 
) 
) 
)

 
HARSHIL U PARIKHHARSHIL U PARIKH
Hello John,
I have been hit something similar in past and I would suggest taking the following approach

1) First make a new formula field named Status_Number__c with return type NUMBER with 0 decimal place on same object and have the formula like below,
CASE( TEXT(Status__c) , 

'Status A', 1, 
'Status B', 2, 
'Status C', 3, 
null)

This way you can use this field (Status_Number__c) inside the validation. Why? Because it is going to give you some ability / Power to use some of the "LESS THAN" Or "GREATER THAN" functions.

2) Change your validation to something like below,
AND( 
    $Profile.Name <> 'Custom', 
    $Profile.Name <> 'System Administrator', 
    CONTAINS(RecordType.Name , "Custom"),
    Status_Number__c < PRIORVALUE(Status_Number__c) 
)
Hope it helps and if it solves the query then please mark it best answer!