You need to sign in to do that
Don't have an account?

S-Control to change case owner using an ACCEPT button on Case Page Layout page
I am trying to change case ownership by providing a custom "ACCEPT" button on the Case Page Layout page so that the user can accept the case without having to go through multiple steps of searching and then accepting the case being reviewed.
To do so, I have created a new S-Control which was placed on the Page Layout for Case object. I am able to display the current field values for this case as you may see from my code. However, when the code attempts to execute the updateCaseOwner() Javascript function, nothing happens. Any clues what I may be doing wrong?
Here is the source code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="/dCSS/Theme2/default/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" >
<link href="/dCSS/Theme2/default/custom.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" >
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="/dCSS/Theme2/default/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" >
<link href="/dCSS/Theme2/default/custom.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" >
<script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript">
/* Author = Komal T
Date = Jan 16, 2009
Description = Use this S Control to change case ownership using an ACCEPT button.
Dependencies = This S-Control utilizes the standard cases object.
*/
function setupPage() {
alert("Inside setupPage, UserID is set to: {!User.Id} and UserName is set to: {!User.Username}");
///this if statement skips getElementById; IE7 can access the resultsHolder element directly by name
if (!document.all){
resultsHolder = document.getElementById('resultsHolder');
}
//search for all cases on the account
alert("Executing the query now....");
var query = "SELECT CaseNumber, OwnerId, Subject, Priority, CreatedDate, Status ";
query = query + " FROM Case WHERE CaseNumber = '{!Case.CaseNumber}' ";
try {
var caseResult = sforce.connection.query(query);
var caseNum = caseResult.getArray("size");
var caseRecords = caseResult.getArray("records");
var newOwnerId = '{!$User.Id}' ;
alert("newOwnerId="+newOwnerId);
} catch (e) {
alert("Error executing SOQL search query: " + e);
}
//display the cases to choose
displayList(caseRecords, caseNum);
updateCaseOwner(caseRecords,caseNum,newOwnerId);
} // End of setupPage
function displayList(caseRecords, caseNum) {
alert("Inside displayList...");
var output = "";
//write out table
output += "<table border=1>";
// output += "<tr class='headerRow'><th> </th><th>Case Number</th><th>Contact</th><th>Subject</th><th>Priority</th><th>Created On</th><th>Status</th><th>Owner</th>";
output += "<tr class='headerRow'><th> </th><th>Case Number</th><th>Owner</th><th>Subject</th><th>Priority</th><th>Created On</th><th>Status</th></tr>";
for (i=0;i<caseNum;i++) {
output += "<tr onmouseover='hiOn(this);' onmouseout='hiOff(this);'><td><input type='checkbox'></td>";
output += "<td>"+caseRecords[i].CaseNumber+"</td>";
output += "<td>"+caseRecords[i].OwnerId+"</td>";
output += "<td>"+caseRecords[i].Subject+"</td>";
output += "<td>"+caseRecords[i].Priority+"</td>";
output += "<td>"+caseRecords[i].CreatedDate+"</td>";
output += "<td>"+caseRecords[i].Status+"</td>";
output += "</tr>";
}
// output += "<input class=btn type='button' value='Next' onclick='displayMergeDetails(document.forms[0]);'>";
output += "</table></form>";
//write HTML to the browser
resultsHolder.innerHTML = output;
} // End of displayList
function updateCaseOwner(caseRecords,caseNum,newOwnerId){
alert("Inside updateCaseOwner...");
for (i=0;i<caseNum;i++) {
// Case myCase = caseRecords[i]
caseRecords[i].OwnerId = newOwnerId ;
sfdc.update(caseRecords);
}// End of for loop
}// End of updateCaseOwner
</Script>
</head>
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>
<script type="text/javascript">
/* Author = Komal T
Date = Jan 16, 2009
Description = Use this S Control to change case ownership using an ACCEPT button.
Dependencies = This S-Control utilizes the standard cases object.
*/
function setupPage() {
alert("Inside setupPage, UserID is set to: {!User.Id} and UserName is set to: {!User.Username}");
///this if statement skips getElementById; IE7 can access the resultsHolder element directly by name
if (!document.all){
resultsHolder = document.getElementById('resultsHolder');
}
//search for all cases on the account
alert("Executing the query now....");
var query = "SELECT CaseNumber, OwnerId, Subject, Priority, CreatedDate, Status ";
query = query + " FROM Case WHERE CaseNumber = '{!Case.CaseNumber}' ";
try {
var caseResult = sforce.connection.query(query);
var caseNum = caseResult.getArray("size");
var caseRecords = caseResult.getArray("records");
var newOwnerId = '{!$User.Id}' ;
alert("newOwnerId="+newOwnerId);
} catch (e) {
alert("Error executing SOQL search query: " + e);
}
//display the cases to choose
displayList(caseRecords, caseNum);
updateCaseOwner(caseRecords,caseNum,newOwnerId);
} // End of setupPage
function displayList(caseRecords, caseNum) {
alert("Inside displayList...");
var output = "";
//write out table
output += "<table border=1>";
// output += "<tr class='headerRow'><th> </th><th>Case Number</th><th>Contact</th><th>Subject</th><th>Priority</th><th>Created On</th><th>Status</th><th>Owner</th>";
output += "<tr class='headerRow'><th> </th><th>Case Number</th><th>Owner</th><th>Subject</th><th>Priority</th><th>Created On</th><th>Status</th></tr>";
for (i=0;i<caseNum;i++) {
output += "<tr onmouseover='hiOn(this);' onmouseout='hiOff(this);'><td><input type='checkbox'></td>";
output += "<td>"+caseRecords[i].CaseNumber+"</td>";
output += "<td>"+caseRecords[i].OwnerId+"</td>";
output += "<td>"+caseRecords[i].Subject+"</td>";
output += "<td>"+caseRecords[i].Priority+"</td>";
output += "<td>"+caseRecords[i].CreatedDate+"</td>";
output += "<td>"+caseRecords[i].Status+"</td>";
output += "</tr>";
}
// output += "<input class=btn type='button' value='Next' onclick='displayMergeDetails(document.forms[0]);'>";
output += "</table></form>";
//write HTML to the browser
resultsHolder.innerHTML = output;
} // End of displayList
function updateCaseOwner(caseRecords,caseNum,newOwnerId){
alert("Inside updateCaseOwner...");
for (i=0;i<caseNum;i++) {
// Case myCase = caseRecords[i]
caseRecords[i].OwnerId = newOwnerId ;
sfdc.update(caseRecords);
}// End of for loop
}// End of updateCaseOwner
</Script>
</head>
<body align="left">
<Table border="0" cellspacing="0" cellpadding="0">
<TR>
<TD class="dataCol" align="left"><font size="-1"><A HREF="#" onclick="javascript:alert('HELLO!!! S Control');setupPage();">Accept Case</A></font></TD>
</TR>
</TABLE>
<div id="resultsHolder">
<h3>Loading cases, please be patient.</h3>
</div>
<Table border="0" cellspacing="0" cellpadding="0">
<TR>
<TD class="dataCol" align="left"><font size="-1"><A HREF="#" onclick="javascript:alert('HELLO!!! S Control');setupPage();">Accept Case</A></font></TD>
</TR>
</TABLE>
<div id="resultsHolder">
<h3>Loading cases, please be patient.</h3>
</div>
</body>
</html>
</html>
1. Put a try/catch block in updateCaseOwner
2. Capture the results of the update statement so you can look at that as well
3. Move your update statement out of the For loop. (Which is what I'm sure you intended.)
4. What is the "sfdc" in sfdc.update and should it be sforce.connection.update?
5. (just a suggestion) Instead of triggering setupPage from a button, you could use the "onload" event on the Body tag.
6. You could use a later version of the API than 10.0, but that should be ok as well.
Then see what error messages you get. Best, Steve.
http://blogs.salesforce.com/support/2008/08/the-contention.html
http://blogs.salesforce.com/support/2008/07/the-quick-case.html
Obviously you'll want to set the owner instead of setting the status, but otherwise the code should be identical. 9 simple lines of code, that's all you need.
Thanks Steve.
You did point out the intended changes and I implemented the same. However, I was unable to narrow down on what exactly the error was related to despite enclosing this in a try...catch block. The most I could get was something like "[sobject] error", nothing specific.
In any case, I tried another solution mentioned by werewolf where it was recommended that I create a new button using Setup-->Customize-->Cases-->Buttons and Links and use the new button to execute custom JavaScript code which does exactly similar stuff. It worked great so I'll carry on with that implementation.
Thanks for all your help.
I am trying to add Accept button on Case.
Where can i find solution. the following link is not working
http://blogs.salesforce.com/support/2008/07/the-quick-case.html
Thanks for the help. Totally worked!