I have the created a visualforce page to display a pop up alert whan a case is closed. Now, I want this alret message to apprea only when a case is closed & not everytime a closed case is refreshed. So I must add a condition to say that the stage value != to old value. Can someone please help ?
<apex:page standardController="Case" showHeader="false" sidebar="false">
<script type="text/javascript">
if(
{!
AND(Case.Status = 'Closed'
)
}
)
{
alert('Please attach a Library Case.');
}
</script>
</apex:page>
You may achieve this as below
1. Old Value : Define a final variable in Apex Class to store Case Status
2. New Value : Passed as parameter to the JS function by the onchange Event
<!-- JAVA SCRIPT-->
<script type="text/javascript">
function alertMessage(status){
if(status != '{!CaseInitialStatus}' && status == 'Closed')
{
alert('Please attach a Library Case.');
}
}
</script>
<! -- Visualforce -->
<apex:inputField value="{!Case.Status}" onchange="alertMessage(this.value);"/>
//APEX CLASS
public final String CaseInitialStatus{get;set;}
//CONSTRUCTOR
objCase = (Case)controller.getRecord();
CaseInitialStatus = objCase.Status;