Campaigns
Campaign definitions are managed by the Sitecore.Marketing.Definitions.Campaigns.CampaignDefinitionManager class.
Accessing the CampaignDefinitionManager
The CampaignDefinitionManager is available from the Sitecore DI container. It is preferable to include a parameter of type DefinitionManagerBase<ICampaignActivityDefinition, CampaignActivityDefinitionRecord> in the constructor of your class and pull your class from the container, allowing the container to resolve the instance for you:
If you cannot use the container to construct your class, you can use the service locator. This class is also available in the Sitecore DI container:
Defining a campaign
A campaign is defined using types from the Sitecore.Marketing.Definitions.Campaigns.Model namespace.
The AutomationStateEnrollmentList will be removed in a later release as automation state enrollment has changed.
Saving a campaign
Once you have defined a campaign you may save it by calling the SaveAsync() method on the definition manager:
You can also optionally activate the campaign during save by passing true to the second parameter of the SaveAsync() method:
Activating a campaign
Campaigns must be activated before they are available for use outside of management, such as being “published” out to the Reference Data Service.
Campaigns can be activated when they’re saved by passing true to the activate (second) parameter of the SaveAsync() method:
Campaigns can also be activated without calling save, using the ActivateAsync() method:
The ActivateAsync() method takes the ID of the campaign and does not require the campaign definition model.
Deleting a campaign
To delete a campaign, use the Delete() method on the manager. Individual cultures cannot be deleted from the definition, only the entire definition. The culture provided to the method call should be either null (default value) or CultureInfo.InvariantCulture.
Or:
Retrieve a campaign
A single campaign can be retrieved by its ID using one of the Get() methods on the manager.
You can also choose to retrieve an inactive version if no active version exists:
Retrieve a campaign by alias
You can also retrieve a campaign by its alias:
Update an existing campaign
To update an existing campaign definition, retrieve the campaign by ID, edit the campaign
Retrieving all campaigns
The GetAll() method can be used to get all campaigns from the manager. As there may be a large number of definitions, this method supports paging. The return value is a single page of results.
To access the results, use the DataPage property of the result.
The result also includes properties to expose the total number of definitions and the current page index and page size.