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
learn_sfdclearn_sfdc 

pop up on status change in case object

Hello Friends,

I am trying to build a pop up alert box in my case object. Whenever my status field is changed to closed, I want to display a pop up. Here's what I have tried so far:

<apex:page standardController="case">
<script>
windows.document.onload = new function(e) {
if({case.JIRA_Status__c= 'Closed'})
{
alert("True");
} else
{ alert("false";) }
}
</script>
</apex:page>
Best Answer chosen by learn_sfdc
LBKLBK
I think what you need is a confirmation prompt, not an alert.

Try this code.
 
<apex:page standardcontroller="case">
<script>
function saveClick() {
var caseStatus = document.getElementById('j_id0:j_id2:CaseStatus');

if(caseStatus.value == 'Closed')
{
    alert("Case is Closed.");
}
}
</script>
<apex:form >
.
.
.YOUR INPUT FIELDS HERE
.
.
.
<apex:commandbutton action="{!save}" value="Save" onclick="javascript:saveClick();"></apex:commandbutton>
</apex:form>

</apex:page>
Look out for the ID of your Case Status field (using Developer Console in your Browser) and populate it in line 4 of the code.

Let me know if this helps.
 

All Answers

LBKLBK
Hi Shruthi,

This is what you need to add in your VF page.
 
<script>
if({case.JIRA_Status__c= 'Closed'})
	{
		alert("True");
	} 
else
	{ 
		alert("false"); 
	}
</script>
This piece of script will be executed when the page is loaded.
 
NagendraNagendra (Salesforce Developers) 
Hi Shruthi,

Please try the below piece of code.
<apex:page standardcontroller="case">

<!-- JS Section -->
<script>
 var caseStatus = '{!case.JIRA_Status__c}';

 window.onload = function () {
   if(caseStatus == 'Closed'){
     // case closed write alert here
     alert('Case is closed');
   }
   else{
     // for else case
   }
 }
</script>
</apex:page>
Best Regards,
Nagendra.
 
rajat Maheshwari 6rajat Maheshwari 6

Hi Shruthi,

Please do the below and let me know the result :)

 

<apex:page standardController="Case" rendered="{!case.JIRA_Status__c=='Closed'}">
 <script type="text/javascript">
  { window.alert("Your message here"); }
 </script>
</apex:page>
 

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com
 

learn_sfdclearn_sfdc
Hello Nagendra,

Im using Status as a field in Case object. Whene ever the status becomes closed, i am trying to display pop up.

but i used below code which is not working :(

<apex:page standardcontroller="case">
<script>
var caseStatus = '{!case.Status}';

 window.onload = function () {
   if(caseStatus == 'Closed'){
     // case closed write alert here
   alert('Case is closed');
  }
else{
   alert('Case is not closed');
 }
}
</script>
</apex:page>
 
learn_sfdclearn_sfdc
Hi Rajat,

No luck, i am trying this pop up on standrad case object, is that a problem, below code is not working?

<apex:page standardController="Case" rendered="{!case.Status=='Solution Provided'}">
<script type="text/javascript">
{
window.alert("Your message here");
}
</script> </apex:page>

 
rajat Maheshwari 6rajat Maheshwari 6

Hi Shruthi,

 

Please do the same for your requirement - 
Go to case and edit case page layout. Drag the suggested visualforce page on page layout. Edit the visualforce page properties and set Height as 0 pixel. (We don't need to show this page to users.) Save the page layout.
 
Let me know if you have any doubts.

Thanks

rajat Maheshwari 6rajat Maheshwari 6
Hi Shruthi,

Have you able to show pop up ? If not, please let me know . I am happy to help you :)

My gmailId : - rajatzmaheshwari@gmail.com

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com
LBKLBK
Are you trying to add this alert to an existing VF page?

If yes, you just need to add the following lines inside the <SCRIPT> tag.
 
if({!case.JIRA_Status__c == 'Closed'})
	{
		alert("True");
	} 
else
	{ 
		alert("false"); 
	}
Any Javascript code outside a function definition will be executed automatically during the page load.

I actually missed an ! symbol in my previous reply.

 
learn_sfdclearn_sfdc
Hello Rajat,

Its working... but it works after clicking on save button.

Can you please suggest me to do before saving the pop up to come.

Thanks,
Shruthi
learn_sfdclearn_sfdc
Hi LBK,

I am trying to create this pop up on existing Standard Case Object.

i trying to write separate VF page.

 
LBKLBK
You can add it to your VF page, in the top <SCRIPT> section.

You can even include the VF page as part of your Page Layouts.

If you still have issues, post your VF page here, we can help you.
learn_sfdclearn_sfdc
Hello LBK,

below code is working fine but the pop up appears after clicking on save button but i would like to get this pop up before saving the case record.

lets say i entered status value and click on save then the pop up should appear(but record should not be saved) then again i should click on 'ok' on pop up box and click save button to save the record.

<apex:page standardcontroller="case">
<script>
var caseStatus = '{!case.Status}';
window.onload = function () {
if(caseStatus == 'Closed')
{
alert ('Case is closed');
}
}
</script>
</apex:page>


 
LBKLBK
I think what you need is a confirmation prompt, not an alert.

Try this code.
 
<apex:page standardcontroller="case">
<script>
function saveClick() {
var caseStatus = document.getElementById('j_id0:j_id2:CaseStatus');

if(caseStatus.value == 'Closed')
{
    alert("Case is Closed.");
}
}
</script>
<apex:form >
.
.
.YOUR INPUT FIELDS HERE
.
.
.
<apex:commandbutton action="{!save}" value="Save" onclick="javascript:saveClick();"></apex:commandbutton>
</apex:form>

</apex:page>
Look out for the ID of your Case Status field (using Developer Console in your Browser) and populate it in line 4 of the code.

Let me know if this helps.
 
This was selected as the best answer
LBKLBK
I mean Developer >> Web console in your browser. This will help you in finding the ID of the inputField which will look similar to "j_id0:j_id2:CaseStatus".
QualzzQualzz
If you need any help for Best Email Pop Ups and any tpyes of pop ups so i suggest you to go with Qualzz. More info visit at https://qualzz.com/