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

Javascript button code to check checkbox?
Hi,
We have a custom Javascript button in our opportunity which creates a case and carries some of the opportunity detail across into the case as it does so.
I have a checkbox field in the opportunity and another in the case, and I want the below code to check the checkbox in the new case being created if the checkbox in the opportunity was checked.
I've tried inserting the line in bold below, but this doesn't work.
Can anyone help here?
TIA
Steve
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
var status = "{!Opportunity.StageName}";
if (
"{!Opportunity.Type}" != "Maintenance - New Agreement" &&
"{!Opportunity.Type}" != "Maintenance - Agreement Renewal" &&
"{!Opportunity.Type}" != "Maintenance - Resi MBF"
){
if (status == "Closed Won") {
var caseToCreate = new sforce.SObject("Case");
caseToCreate.AccountId = "{!Opportunity.AccountId}";
caseToCreate.Type = "{!Opportunity.Type}";
caseToCreate.Subject = "{!Opportunity.Name}";
caseToCreate.Origin = "Converted Opportunity";
caseToCreate.Description = "{!Opportunity.Requirement__c}";
caseToCreate.Related_Opportunity__C = "{!Opportunity.Id}";
caseToCreate.ContactId = "{!Opportunity.Opportunity_ContactId__c}";
caseToCreate.RecordTypeId = "01230000001DNJc";
caseToCreate.Case_Value__c = "{!TEXT(Opportunity.Amount)}";
caseToCreate.Case_Parts_Required__c = "{!Opportunity.Opp_Parts_Required__c}";
result = sforce.connection.create([caseToCreate]);
if(result[0].success == "true"){
alert("Case has been created.");
}
else{
alert("Error: " + result[0].errors.message);
}
} else {
alert(
"Opportunity must be won " +
"before a case can be created."
);
}
} else
alert(
"A case cannot be created for maintenance opportunities, " +
"other than ad-hoc maintenance visits. " +
"For maintenance opportunites, please use the " +
"Create Contract button."
);
We have a custom Javascript button in our opportunity which creates a case and carries some of the opportunity detail across into the case as it does so.
I have a checkbox field in the opportunity and another in the case, and I want the below code to check the checkbox in the new case being created if the checkbox in the opportunity was checked.
I've tried inserting the line in bold below, but this doesn't work.
Can anyone help here?
TIA
Steve
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
var status = "{!Opportunity.StageName}";
if (
"{!Opportunity.Type}" != "Maintenance - New Agreement" &&
"{!Opportunity.Type}" != "Maintenance - Agreement Renewal" &&
"{!Opportunity.Type}" != "Maintenance - Resi MBF"
){
if (status == "Closed Won") {
var caseToCreate = new sforce.SObject("Case");
caseToCreate.AccountId = "{!Opportunity.AccountId}";
caseToCreate.Type = "{!Opportunity.Type}";
caseToCreate.Subject = "{!Opportunity.Name}";
caseToCreate.Origin = "Converted Opportunity";
caseToCreate.Description = "{!Opportunity.Requirement__c}";
caseToCreate.Related_Opportunity__C = "{!Opportunity.Id}";
caseToCreate.ContactId = "{!Opportunity.Opportunity_ContactId__c}";
caseToCreate.RecordTypeId = "01230000001DNJc";
caseToCreate.Case_Value__c = "{!TEXT(Opportunity.Amount)}";
caseToCreate.Case_Parts_Required__c = "{!Opportunity.Opp_Parts_Required__c}";
result = sforce.connection.create([caseToCreate]);
if(result[0].success == "true"){
alert("Case has been created.");
}
else{
alert("Error: " + result[0].errors.message);
}
} else {
alert(
"Opportunity must be won " +
"before a case can be created."
);
}
} else
alert(
"A case cannot be created for maintenance opportunities, " +
"other than ad-hoc maintenance visits. " +
"For maintenance opportunites, please use the " +
"Create Contract button."
);
Can you check the field API names(Case_Parts_Required__c & Opp_Parts_Required__c ) are correct or not?
Thanks!!
In the opportunity we have Opp_Parts_Required__c
In the case we have Case_Parts_Required__c
The button is on the opportunity page, and when I click it, I want the checkbox on the new case being created to be checked, if the checkbox on the opportunity is checked.
Thanks
I have tried the below code by removig some of the custom fields and its working.
Can you please check the remaining fields API names and try.
Thanks!!
Can you please check, is there any validation rules are restricting while creation of case.
Thanks!!