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
LaaralLaaral 

Workflow rule problem

Hi, I need to do a workflow (or validation rule I'm not sure which one to use) and it should do this "Setup status can be saved as "Cancelled" only if prior value has been "In delivery".
But when I do it like this the first Error goes : Extra " , " then when I take it off it says "Extra Pickval" 

AND(ISCHANGED(Setup_Status__c), "Cancelled"),
ISPICKVAL(PRIORVALUE(Setup_Status__c), "In Delivery"))

What would be a better solution for this?
Best Answer chosen by Laaral
CheyneCheyne
Sorry, my mistake. You need to use the ISPICKVAL function to get at the value of Setup_Status__c in the PRIORVALUE function.

ND(ISCHANGED(Setup_Status__c), ISPICKVAL(Setup_Status__c, "Cancelled"), NOT(ISPICKVAL(PRIORVALUE(Setup_Status__c), "In Delivery")))

All Answers

CheyneCheyne
Sounds like this should be a validation rule. I would write it like this (assuming Setup_Status__c is a picklist field): 

AND(ISCHANGED(Setup_Status__c), ISPICKVAL(Setup_Status__c, "Cancelled"), NOT(PRIORVALUE(Setup_Status__c) = "In Delivery")

If a user tries to save the record and this criteria evaluates to true, an error message will be displayed. It will evaluate to true if Setup Status is equal to "Cancelled" and the previous value of Setup Status was not equal to "In Delivery". Furthermore, it also checks if Setup Status was actually changed in this update, since if it was not, I assume you don't need to run the validation (if you do, you can remove the ISCHANGED() part). 
LaaralLaaral
Hi Cheyne, this validation rule fires the error message even when I'm changing the Setup Status from In Delivery to Cancelled ? It shouldn't show any error messages, it should show error message only when the status is for example not in invoicing and someone is trying to change it to cancelled.
CheyneCheyne
Sorry, my mistake. You need to use the ISPICKVAL function to get at the value of Setup_Status__c in the PRIORVALUE function.

ND(ISCHANGED(Setup_Status__c), ISPICKVAL(Setup_Status__c, "Cancelled"), NOT(ISPICKVAL(PRIORVALUE(Setup_Status__c), "In Delivery")))
This was selected as the best answer