Here is the script I'm currently working with unsuccessfully.
{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}
getDate = function(dateObj){
var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay();
var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth();
return dateObj.getFullYear()+'-'+month+'-'+day;
}
var campaignMember = new sforce.SObject('CampaignMember');
campaignMember.CampaignId = '00xxx0000xxx000';
campaignMember.LeadId = '{!Lead.Id}';
campaignMember.Lead = '{!Lead.Name}';
campaignMember.Status = 'Sent';
result = sforce.connection.create([campaignMember]);
if(result[0].success == 'true'){
alert(campaignMember.CampaignId+' has been added to Campaign.');
}
2 respuestas
Hello, Patrick, I think you have the right idea. What's probably creating the problem is your attempt to set campaignMember.Lead to a string value. Everything else looks pretty good. I tested some simplified code[1] for a sample button in my DE org, and it appeared to work as expected.
[1]: some simplified code (
http://pastebin.com/UqmQWvfX)