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

Cross Objects validation rule

I have a custom object (Service Request) has a master detail relationship to the Case object.  What I am trying to do is to prevent a user from closing a case if the related service request record does not have a status of "awaiting invoice"  This status field in my custom object is a picklist.  This is the code that I have attempted to enter and the error message I get when I try to validate it.

AND(ISPICKVAL( Status ,"Closed - Resolved"), NOT(ISPICKVAL ($ObjectType.Service_Request__c.Fields.Status__c, "Awaiting Invoice")))

Incorrect parameter for function ISPICKVAL(). Expected Picklist, received Object

Any help/suggestions would be appreciated.

You can't use formulas for validations across objects right now, excepting the use of Roll Up Summary formulas. You'll need to use Apex Code if you want to cause this to work as expected. See the relevant feature request.
Thanks for letting me know.
Or else you can assign an S-control to Close Case Button.
In S-control you have to retrieve the related records for a case and check the staus value.If status is 'Awaiting' throw a erroe msg saying 'case cannot be closed' and redirect back to case page.Else redirect to Standard case close page(If all the related records are closed).This is very simple.
Since you can't add an s-control to the close page layout, how would you get the s-control to fire when someone goes to close the case?
Bit late on this reply, but the answer is not to place on the close page layout, but override the button itself. Setup | App Setup | Customize | Cases | Buttons and Links. Choose the Override option for Close Case, and there you have it. Example S-Control follows.
if('{!Case.Status}' == 'Awaiting')
{ alert('You can not close this case right now.') = '/{!Case.Id}'
{ = '{!URLFor(Case.CloseCase,Case.Id,[retURL='/'&Case.Id,true)}'