+ Start a Discussion
Rod AtienzaRod Atienza 

Why is my Custom Button Javascript field not updated

I have a custom button (close case) that does some validations before a user can go into the close layout screen. The button, behaviour is execute javascript, references a rollup summary field on a releated list. The problem is with the contact center using service cloud. So when i open the case, the rollup summary is 1 for example. I will open up the related list record, which opens on another tab in salesforce, and do an update to the record and save. When i go back to the case tab the value of the rollup field i see is updated to 2. However when I hit custom button, the value of the rollup summary is still 1. It only after  a refresh of the page that the javascript will see the new value.
How can i get the true value without having the user manually refreshing the screen.
 
Best Answer chosen by Rod Atienza
SarfarajSarfaraj
Use this instead,
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}
var caseDetails = sforce.connection.query("SELECT Id, Case_Serial_Resolution_Code__c, Case_Serial_Count__c FROM Case Where Id = '{!Case.Id}'").getArray("records");
 if (caseDetails[0].Case_Serial_Resolution_Code__c !=  caseDetails[0].Case_Serial_Count__c)
 {
     alert('Case cannot be closed without adding a Resolution Code to the Case Serial Number (s).' + caseDetails[0].Case_Serial_Resolution_Code__c);
 }

 

All Answers

SarfarajSarfaraj
It seems to me that it is referencing the field value in static manner. You have to query the current value of the rollup field at runtime. Can you please post the javascript code of your button. I will try to fix it.
Rod AtienzaRod Atienza
  if ({!Case.Case_Serial_Resolution_Code__c}  !=  {!Case.Case_Serial_Count__c})
  {
     alert('Case cannot be closed without adding a Resolution Code to the Case Serial Number (s).' + {!Case.Case_Serial_Resolution_Code__c});
  }
SarfarajSarfaraj
Use this instead,
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}
var caseDetails = sforce.connection.query("SELECT Id, Case_Serial_Resolution_Code__c, Case_Serial_Count__c FROM Case Where Id = '{!Case.Id}'").getArray("records");
 if (caseDetails[0].Case_Serial_Resolution_Code__c !=  caseDetails[0].Case_Serial_Count__c)
 {
     alert('Case cannot be closed without adding a Resolution Code to the Case Serial Number (s).' + caseDetails[0].Case_Serial_Resolution_Code__c);
 }

 
This was selected as the best answer
Rod AtienzaRod Atienza
Thanks, that worked