You need to sign in to do that
Don't have an account?
Laura StanleyHubbard
Javascript Triggering error for Button Added on Contact Detail Page
I've added a custom button to the Contact Detail view, and I'm startig to test it's functionality. I want it to open a case and have the status default to closed.I get the error, when click on contact page, "An error has occurred. Error: Id not specific in an update call." My code is below:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
try{
var caseToUpdate = new sforce.SObject("Case");
caseToUpdate.Id = "{!Case.Id}";
caseToUpdate.Status = "Closed";
var result =
sforce.connection.update([caseToUpdate]);
if(result[0].success == "true"){
location.reload();
}
else{
alert("An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
try{
var caseToUpdate = new sforce.SObject("Case");
caseToUpdate.Id = "{!Case.Id}";
caseToUpdate.Status = "Closed";
var result =
sforce.connection.update([caseToUpdate]);
if(result[0].success == "true"){
location.reload();
}
else{
alert("An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}
Practically, you need to provide a subject for this case or other information. ie.
caseToUpdate.Subject = "Lauran's case";
I now have new updated code that reflects new business requirements. However, when I run, I get the following error: Expected Identifier. Some additional information might help: All fields except subject and description are picklist fields. 3 are custom/dependent fields. Also, I need this to ensure that the case is opened and revealed in another tab and not just created in the system to go find. There are addiional steps that have to happen manually or with a macro post this button click. Suggestions on error and viewing the case on click?
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
try{
var caseToUpdate = new sforce.SObject("Case");
caseToUpdate.Status = "Open";
caseToUpdate.Subject = "Benefit Confirmation Statement";
caseToUpdate.Description = "Benefit Elections edited. Confirmation Statement created and sent to WSE via email";
caseToUpdate.{!Case.Service__c} = "Health and Welfare";
caseToUpdate.{!Case.Action__c} = "Enrollment";
caseToUpdate.{!Case.Case_Contact_Type__c} = "WSE";
caseToUpdate.Origin = "Internal";
caseToUpdate.Priority = "Low";
caseToUpdate.Type_c = "Eligibility";
var result = sforce.connection.create([caseToUpdate]);
if(result[0].success == "true"){
location.reload();
}
else{
alert("An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}
1. Pull over the contact name, contact email (when available), phone, mobile, and fax, and the account name tied to that contact when this case is created.
2. I also need the new case to display. Is javascript the way to go here?
In the code, you can pass the contact information to new case. the example below is passing contact name to case subject field.
caseToUpdate.Subject = "{!Contact.Name}";
To redirect to the new case page, use result[0].id to get the new case id.
if(result[0].success == "true")
{
//location.reload();
location.href="/" + result[0].id;
}