+ Start a Discussion
sam_Adminsam_Admin 

Priorvalue in Validation rule

Hi Folks,
      Iam trying to simplify my validation rule but i get error. My VR restricts users from role from chaning ownerid for subset of users, since all my users first name is "TBD" i want to simpify the rule by adding owner.firstname, here is my rule

AND(
     OR($UserRole.Id  = "00E30000000vEST",
        $UserRole.Id  = "00E40000001CZB5"),
        ISCHANGED(OwnerId),
        PRIORVALUE(OwnerId) <> "00540000000zpgS",
        PRIORVALUE(OwnerId) <> "00540000000oWNX",
        PRIORVALUE(OwnerId) <> "00540000000lkIN",
        PRIORVALUE(OwnerId) <> "00540000001SyUq",
        PRIORVALUE(OwnerId) <> "00540000001UnYg",
        PRIORVALUE(OwnerId) <> "00540000002FltR",
        PRIORVALUE(OwnerId) <> "00540000002nKbr",
        PRIORVALUE(OwnerId) <> "00540000002JAiR",
        PRIORVALUE(OwnerId) <> "00540000002IeDq",
        PRIORVALUE(OwnerId) <> "00540000002nU49",
        PRIORVALUE(OwnerId) <> "00540000002nU4Y",
        PRIORVALUE(OwnerId) <> "00540000002nU4T"
)

I want to use PRIORVALUE(Owner.FirstName <> "TBD") but i get this error "Incorrect argument type for function 'PRIORVALUE()'."

Any help is appreciated.
Best Answer chosen by sam_Admin
sbbsbb
Like I said, the 'Test__c' field should be in the Opp object, and not in the User object. If you want Test__c to contain Opp owner's first name, write this formula for the Test__c formula field:
Owner.FirstName
And then you can VR formula can use this field like this: PRIORVALUE(Test__c) <> "TBD"

Hope that helps.

All Answers

sbbsbb
PRIORVALUE(Owner.FirstName)

sam_Adminsam_Admin
That is what i used but i get that error
sbbsbb
I posted too soon without completing my answer. The error you are getting is due to the syntax error (you needed closing parenthesis immediately after FirstName). 

However, I am not sure you can use PRIORVALUE for checking the owner's first name in this way.
sbbsbb
You can probably add a formula field that computes the owner's first name and then use that in your VR:
PRIORVALUE(Owner_Firstname__c) <> "TBD"

sam_Adminsam_Admin
Iam still not able to use formula or even text field in priorvalue function
sbbsbb
Can you post the complete formula along with the error message here?
sam_Adminsam_Admin
Test__c is formula field.

AND(
     OR($UserRole.Id  = "00E30000000vEST",
        $UserRole.Id  = "00E40000001CZB5"),
        ISCHANGED(OwnerId),
        PRIORVALUE(OwnerId) <> "00540000001SyUq", 
        PRIORVALUE(OwnerId) <> "00540000001UnYg", 
        PRIORVALUE(OwnerId) <> "00540000002FltR", 
        PRIORVALUE(Owner.Test__c) <> "TBD"
    )

Error: The PRIORVALUE function cannot reference the Owner.Test__c field.
sbbsbb
The field 'Test__c' that contains the formula computing owner's first name should be in the object for which you are writing this validation rule. Once that is done, you can replace the last line in the above validation rule with this:
PRIORVALUE(Test__c) <> "TBD"

sam_Adminsam_Admin
Not sure if that works, because if my user is trying to change the ownerid of opp then how it would trigger since this field is on user object not on Opp right?
sam_Adminsam_Admin
Btw even PRIORVALUE( $User.Test__c ) <> 'TBD' doesn't works ,it gives me this error

Error: The PRIORVALUE function cannot reference the $User.Test__c field.
sbbsbb
Like I said, the 'Test__c' field should be in the Opp object, and not in the User object. If you want Test__c to contain Opp owner's first name, write this formula for the Test__c formula field:
Owner.FirstName
And then you can VR formula can use this field like this: PRIORVALUE(Test__c) <> "TBD"

Hope that helps.
This was selected as the best answer
sam_Adminsam_Admin
Thanks it worked