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
Michael VillegasMichael Villegas 

Validation Rule - Restrict value change for select values

Hello!

Attempting a script that allows the user to pick values freely with the exception of 3 values. If the users selects any of the 3 defined values, restrict the user from make any further revisions to the picklist. 

Below is my current attempt, this works to keep the user from selecting the 3 defined values per their user role, however I'm trying to allow them to select the value but then "lock" the value once it has been selected. Does this scenerio sound feasible via validation rule? 

AND((CONTAINS($UserRole.Name,'Contractor')), 
OR(ISPICKVAL(eo2__Project_Status__c, 'Work Complete') 
,ISPICKVAL(eo2__Project_Status__c, 'Batched') 
,ISPICKVAL(eo2__Project_Status__c, 'Incentive Authorized') 
))

Any help would be appreciated!

Thanks!

Michael
Best Answer chosen by Michael Villegas
Glyn Anderson 3Glyn Anderson 3
Michael,  You need to use the ISCHANGED and PRIORVALUE functions in your formula.  The formula below will be true if the user is a contractor, the project status has changed, and the previous value of the picklist was one of the 3 values.  This should prevent contractors from being able to change the status once it is one of the 3 values.

<pre>
AND
( CONTAINS( $UserRole.Name, 'Contractor' )
, ISCHANGED( eo2__Project_Status__c )
, OR
  ( ISPICKVAL( PRIORVALUE( eo2__Project_Status__c ), 'Work Complete' )
  , ISPICKVAL( PRIORVALUE( eo2__Project_Status__c ), 'Batched' )
  , ISPICKVAL( PRIORVALUE( eo2__Project_Status__c ), 'Incentive Authorized' )
  )
)
</pre>

All Answers

Raj VakatiRaj Vakati
HI Michael, 
With Validation rule, you can not able to lock the record. 
You can use Approval process lock action on Status Change to lock the record and use filed history to track the changes. 

 
Michael VillegasMichael Villegas
Thanks Raj! I might have to look into that. However, how about restricting the field from being changed once any of the 3 values are selected? 
Raj VakatiRaj Vakati
In that case instead of validation rule , Use before trigger and Approval process together .Move your validation rule logic in trigger 
Glyn Anderson 3Glyn Anderson 3
Michael,  You need to use the ISCHANGED and PRIORVALUE functions in your formula.  The formula below will be true if the user is a contractor, the project status has changed, and the previous value of the picklist was one of the 3 values.  This should prevent contractors from being able to change the status once it is one of the 3 values.

<pre>
AND
( CONTAINS( $UserRole.Name, 'Contractor' )
, ISCHANGED( eo2__Project_Status__c )
, OR
  ( ISPICKVAL( PRIORVALUE( eo2__Project_Status__c ), 'Work Complete' )
  , ISPICKVAL( PRIORVALUE( eo2__Project_Status__c ), 'Batched' )
  , ISPICKVAL( PRIORVALUE( eo2__Project_Status__c ), 'Incentive Authorized' )
  )
)
</pre>
This was selected as the best answer
Michael VillegasMichael Villegas
That did the trick Glyn! I attempted a few variations with the PRIORVALUE, but I was missing the ISCHANGED - very insightful. Thanks again!