APIs & Integrations

brandensilva
Member

Dynamically set Salesforce Campaign ID (sfdcCampaignId) from URL

Currently a customer of mine who uses Hubspot sets their sfdcCampaignId via the embed code at the time of form creation.

What they want to accomplish is being able to pass this id in via a URL to dynamically populate this ID on the form on page load. This way they can use this same form but have it associate with different Salesforce Campaign IDs.

I’ve been told the sfdcCampaignId is a hidden field but I’m guessing it is dynamically generated on the fly at the time of submission as I’m not able to locate it as an actual form field.

I’m trying to avoid going through the Forms API route and wondering if this is possible to do via onFormReady or onForm Submit callbacks in any way?

0 Upvotes
3 Replies 3
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Dynamically set Salesforce Campaign ID (sfdcCampaignId) from URL

Hi @brandensilva,

You can rebuild the form by calling the create method again after grabbing the sfdcCampaignId from the URL. Rob describes a similar process for updating the redirectUrl of a form here:

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Dynamically set Salesforce Campaign ID (sfdcCampaignId) from URL

Hi @brandensilva,

Salesforce campaign is handled differently than other fields; it’s included in the form create method. In theory you could dynamically edit this using Javascript by rebuilding the form create code. An example of what this code looks like is:

hbspt.forms.create({
    portalId: 'xxxxxxx',
    formId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
     sfdcCampaignId: "xxxxxxxxxxxxxxxxxx"
  }); 
0 Upvotes
brandensilva
Member

Dynamically set Salesforce Campaign ID (sfdcCampaignId) from URL

Hey Derek,

Yeah this was one approach we were throwing around that seemed possible but not ideal since a lot of the form creation process would be offset to the developer side. We’d also have to sort out how to get the portalId and formId that match from Hubspot into the dynamic creation of the form.

Is there no way for us to manipulate the sfCampaignId during init or after the form loads? Are you stashing the sfdcCampaignId anywhere that I can access it to update it based on the URL? In this case it might be necessary perhaps if you are loading this sfcdCampaignId up in a text string for me to parse that field, manipulate the campaignId based on the URL, then add the string back into the property.

0 Upvotes