function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Maciej GuniaMaciej Gunia 

Javascript button to update Campaign Member field

Hello,

 

I am trying to create a javascript button which will first update a field in the Campaign Member level and then open the page of the new opportunity wizard. I found on the internet the code whcih I used to amend. However, the code returns the error about unexpected identifier:

 

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

var c = new sforce.SObject("CampaignMember");
c.id = "{!CampaignMember.Id}";
c.Proposal_Sent__c = true;
result = sforce.connection.update([c]);

window.location.reload();

 

Could any of you help me what should be changed in this code to make it work. I expect CampaignMember brings here the confusion and probably it should be coded differently.

Sonam_SFDCSonam_SFDC
Hi,

I tested this on my ORG - looks like you got this code from where this was a button on a visualforce page which si the reaosn why the ID can be accessed directly using merge field.

If you wish to add this on a standard page - you will have to first fetch the ID on the campaign member from the URL using something as defined on the link : http://www.joezimjs.com/javascript/3-ways-to-parse-a-query-string-in-a-url/ then update the campaign member.