I need to assign an Entitlement to all Cases created from an Opportunity, when a user clicks a custom button.
I've created a custom field on the Account which contains the Entitlement Id Application_Entitlement_ID__c that will be used in order to populate the Case lookup field EntitlementId. But I can't work out how to fetch that value, without adding a formula field on the Opportunity, which I'm keen to avoid.
This post Related Object Fields in custom button (URL Hack) probably contains the solution but I'm new to JavaScript and the use case and code are too complicated for me to adapt, in order to solve my issue.
Here's the code that I've written so far -
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
try{
var recToCreate = new sforce.SObject("Case");
recToCreate.RecordTypeId = "012180000004Kle";
recToCreate.OwnerId = '00G18000000Ntra';
recToCreate.AccountId = '{!Opportunity.AccountId}';
recToCreate.Subject = '{!Opportunity.Name}';
recToCreate.Origin = "Customer Application";
recToCreate.Opportunity__c = '{!Opportunity.Id}';
recToCreate.User__c = '{!Opportunity.OwnerId}';
var result = sforce.connection.create([recToCreate]);
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);
}