0

I have a button that assigns a case back to the originator. When a user clicks on the button, they have no other choice but to go through with the action after they select OK on the JS alert. How do I add an option for the user to click Cancel and return to the record in the following code?

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 

if ({!Case.OwnerId=Case.CreatedById}){ 
alert('You are already the owner of the case'); 
} else { 

var caseObj = new sforce.SObject("Case"); 
var result = sforce.connection.update([caseObj]); 

if (result[0].success=='false') { 
alert(result[0].errors.message); 
} else { 
//location.reload(true); 
alert ('This case will be assigned back to the creator. You will no longer have access to this case.'); 
window.location = '/500/o'; 
} 
}
3

You can use the confirm method to allow an option for them to abort before it happens.

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 

if ({!Case.OwnerId=Case.CreatedById}) { 
  alert('You are already the owner of the case'); 
} else if( confirm('This case will be assigned back to the creator. You will no longer have access to this case. Are you sure?')) { 
  var caseObj = new sforce.SObject("Case"); 
  var result = sforce.connection.update([caseObj]); 

  if (result[0].success=='false') { 
    alert(result[0].errors.message); 
  } else { 
    window.location = '/500/o'; 
  } 
}
  • thanks so much. After I click OK, I get an error that says "ID not specified in an update call". Is there something I'm missing in the ID? – Paul Jan 24 '17 at 17:05
  • nevermind! I added the ID and the createdbyId and it is now working. Thank you so much! – Paul Jan 24 '17 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.