Salesforce Marketing Cloud

Link campaign to delivery send

Link campaign to delivery send

Are you aware of Salesforce Marketing Cloud’s additional marketing feature known as Campaign? This tool allows you to group similar journeys together, providing greater organization for your marketing activities.

However, one drawback is that the campaign information is not available in the data views. While waiting for a fix from Salesforce, you can establish a link within the platform using the following workaround.

Get campaign list

To get campaign list we need to use REST API to get all campaign as such information is not available in any data view as well.

Before that we create package with Server-to-Server type component in Marketing Cloud setup and add the following scope to it:

  • Data Extensions: Read, Write
  • Campaign: Read

Create data extension to store campaign data:

  • name and external key should be the same. In my case I use prefix_campaigns both external key and name

Once we have a package with our client secret and client id we can move on to create SSJS GET request call to receive campaigns and save them to our data extension.

<script runat="server">
   Platform.Load("core", "1");
   var getToken = function(setup) {
       var config = {
           url : setup.authBaseURI + "v2/token",
           contentType : "application/json",
           payload : {
               "client_id": setup.clientId,
               "client_secret": setup.clientSecret,
               "grant_type": "client_credentials"
       var req = HTTP.Post(config.url, config.contentType, Stringify(config.payload));
       if (req.StatusCode == 200) {
           var res = Platform.Function.ParseJSON(req.Response[0]);
           return res.access_token;
       return false;
   performGetRequest = function(url, config, token) {

        var req = new Script.Util.HttpRequest(url);
            req.emptyContentHandling = 0;
            req.retries = 2;
            req.continueOnError = true;
            req.setHeader("Authorization", "Bearer " + token);
            req.method = "GET";
            req.contentType = config.contentType;
            req.encoding = "UTF-8";

        var res = req.send();
        return Platform.Function.ParseJSON(String(res.content));
    getCampaigns = function(token, setup) {
        var currentPage = 1,
        perPage = 50,
        config = {
            contentType : "application/json",
            headerName : ["Authorization"],
            headerValue : ["Bearer " + token]   
        campaigns = [],
        nextPage = true;
            nextPage = false;
            var url = setup.restBaseURI + "hub/v1/campaigns?$page="+currentPage+"&$pageSize="+perPage,
                res =   performGetRequest(url, config, token);
            if (res && res.items.length){
                for (var i = 0;i<res.items.length;i++)
                nextPage = true;
        return campaigns;
    setup = {
        restBaseURI: "https://<EXAMPLE>",
        clientId : "<EXAMPLE>",
        clientSecret: "<EXAMPLE>"
    token = getToken(setup),       
    campaigns = getCampaigns(token, setup),
    rows = [],
    campaignDe =  DataExtension.Init("campaigns"),
    deliveries = [];

    for (var i = 0;i<campaigns.length;i++){
        if(!campaignDe.Rows.Lookup(["id"], [campaigns[i].id],1))

More information about the campaigns GET request

Get campaign ids mapped to delivery send id

This part is a bit strange as I would think that campaign id information is available on data views but it is not and only way how to access this information is with help of tracking extract.

Create “Data extract” activity

Extract typeTracking Extract
Format csv
Column Delimiter[comma]

Check the following options:

  • Extract sent
  • Include Campaign ID

Create “File transfer” activities

This file transfer is just to move our extracted file from the safe house to sftp. We will use the same pattern defined before and destination we can select Export

Settings for file transfer activity

Create another file transfer activity that its function will be to extract the archived export. As before we will use the same file name pattern

Create “File import” activity

Last but not least we need to create file import that actually will take the campaign id and send id and stores it in data extension with only two columns and both set as primary key. This will deduplicate the unnecessary rows for us. Also if desired set the data retention policy before you create the data extension.

  • name and external key should be the same. In my case I use prefix_Sends_To_Campaign_Map both external key and name
Campaign to delivery mapping data extension

Set default import folder to take extracted file from.

Extract typeTracking Extract
File patternSent.csv
Respect double quotes ” as delimiterchecked
Settings for file import

Mapping can be set as Map by ordinal if you do not want to load sample file nor store all columns in your DE (they are not needed as campaign id is taken from sent log and we do not need information like subscriber key)

Data action set to Add only so the automation will automatically not store row that are already saved.

Reconcile with _Job data view

Now that we have both tables and we can easily map campaign information to our send data extension and reconcile with _Job data view

SendId from Sends_To_Campaign_Map DE is equal to the JobId on _Job view

FROM _Job as J
LEFT JOIN prefix_Sends_To_Campaign_Map as STCM on J.JobID = STCM.SendID
LEFT JOIN prefix_campaigns CMP on STCM.CampaignId =

Oh hi there 👋
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

We don’t spam! Read our privacy policy for more info.

#data views #programming #SQL #ssjs
Marcel Szimonisz
Marcel Szimonisz
MarTech consultant As a marketing automation consultant, I specialize in problem-solving, process automation, and driving innovation for clients' marketing platforms.

I hold certifications in Adobe Campaign v6 (3x certified) and Salesforce Marketing Cloud (5x certified), as well as 1x Salesforce Associate certified.

Moreover, I serve as a community advisor for Adobe Campaign, providing expert insights and guidance.

Beyond my professional pursuits, I explore various programming languages, CMSs, and frameworks, enhancing my technical expertise and staying at the forefront of industry advancements.
Take a look at our subscription offering in case you are looking for a Marketing Automation Consultant.

Leave a comment

Your email address will not be published. Required fields are marked *

Similar posts that you may find useful

Consent management in SFMC explained
Marketing Automation, Salesforce Marketing Cloud

Consent management in SFMC explained

6 minutes read

Even after a couple of years working with Salesforce Marketing Cloud, I am still somewhat lost on how the consent management works. I’ve decided to tackle all the uncertainties I’ve been avoiding since I first started. Let’s dive into this topic and resolve all doubts once and for all. As you might have noticed, there […]

Continue reading
SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Invalid links in email template

1 minute read

When the HTML template is used (loading your own HTML code) all the links that use query parameters (?a=b) will resolve to invalid links when they redirect upon user click. This happens when web analytics UTM tags are being attached to the delivery. To resolve this issue all the links with additional query parameters has […]

Continue reading
SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Validation issues With Data Extension Columns _dat, _call, _from

less than a minute read

Data extension column names with _dat, _call, _from, _join suffix will fail to validate, due to using old style JOIN The fix is really easy you only need to wrap the column name like [test_from] and the problem with validation is history If you know more suffixes that will throw an error let me know

Continue reading
Salesforce Marketing Cloud Tips
Journey builder, Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Refresh Delivery in Transactional Journey

1 minute read

The process might seem straightforward at first glance—simply refreshing the email delivery content in Salesforce Marketing Cloud should suffice to receive the updated email contents. However, there’s more to consider. Salesforce Marketing Cloud utilizes server-side caching, which may display outdated content. Understanding when the cache refreshes isn’t always clear. In scenarios where immediate changes are […]

Continue reading
How to use journey exit criteria and goals
Marketing Automation, Salesforce Marketing Cloud

How to use journey exit criteria and goals

3 minutes read

I might be really slow learning but I learned about this feature two years into working with salesforce marketing cloud, and I said to myself what a nice feature to have. Let me tell you what it is and give you some real life examples when to use it. Exit criteria and goals share a […]

Continue reading