Outcomes

Current version: 9.0

Outcome definitions are managed by the Sitecore.Marketing.Definitions.Outcomes.OutcomeDefinitionManager class.

Note

Outcomes are specialized events. IOutcomeDefinition inherits IEventDefinition.

Accessing the OutcomeDefinitionManager

The OutcomeDefinitionManager is available from the Sitecore DI container. It is preferable to include a parameter of type DefinitionManagerBase<IOutcomeDefinition, OutcomeDefinitionRecord> in the constructor of your class and pull your class from the container, allowing the container to resolve the instance for you:

RequestResponse
public MyClass(DefinitionManagerBase<IOutcomeDefinition, OutcomeDefinitionRecord> outcomeDefinitionManager)
{
        ...
}

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:

RequestResponse
using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;

ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<IOutcomeDefinition>();

Defining a outcome

A outcome is defined using types from the Sitecore.Marketing.Definitions.Outcomes.Model namespace.

RequestResponse
Guid outcomeId = Guid.NewGuid(); // Outcome ID
CultureInfo outcomeCulture = new CultureInfo("es"); // Outcome culture
string outcomeName = "Newly created outcome"; // Outcome name
DateTime creationDate = DateTime.UtcNow; // Outcome creation date
string createdBy = "sitecore\admin"; // Outcome creator

OutcomeDefinition outcome = new OutcomeDefinition(outcomeId, "Outcome item name", outcomeCulture, outcomeName, creationDate, createdBy);

outcome.IsMonetaryValueApplicable = true;
Note

IsMonetaryValueApplicable is used in reporting. It is valid to have an outcome with no meaningful monetary value, such as a contract signed or commitment made. In these instances, set IsMonetaryValueApplicable to false.

AdditionalRegistrationsAreIgnored was used by the OutcomeManager and is no longer in use. Please remove this property from your code.

Live events

The IsLiveEvent property is part of the base EventDefinition class and is used by Marketing Automation to determine if an event should be processed immediately rather than on session end. Read more about live event processing.

Saving a outcome

Once you have defined a outcome you may save it by calling the SaveAsync() method on the definition manager.

RequestResponse
Guid outcomeId = Guid.NewGuid(); // Outcome ID
CultureInfo outcomeCulture = new CultureInfo("es"); // Outcome culture
string outcomeName = "Newly created outcome"; // Outcome name
DateTime creationDate = DateTime.UtcNow; // Outcome creation date
string createdBy = "sitecore\admin"; // Outcome creator

OutcomeDefinition outcome = new OutcomeDefinition(outcomeId, "Outcome item name", outcomeCulture, outcomeName, creationDate, createdBy);

outcome.IsMonetaryValueApplicable = true;

    OutcomeDefinitionManager manager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<IOutcomeDefinition>();

manager.SaveAsync(outcome);

You can also optionally activate the outcome during save by passing true to the second parameter of the SaveAsync() method:

RequestResponse
manager.SaveAsync(outcome, true);

Activating a outcome

Outcomes must be activated before they are available for use outside of management. Outcomes can be activated when they’re saved by passing true to the activate (second) parameter of the SaveAsync() method:

RequestResponse
manager.SaveAsync(outcome, true);

Outcomes can also be activated without calling save, using the ActivateAsync() method:

RequestResponse
manager.ActivateAsync(outcomeId);

The ActivateAsync() method takes the ID of the outcome and does not require the outcome definition model.

Deleting a outcome

To delete a outcome, 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.

RequestResponse
manager.Delete(outcomeId);

Retrieve a outcome

A single outcome can be retrieved by its ID using one of the Get() methods on the manager.

RequestResponse
Guid outcomeId = Guid.NewGuid(); // Ensure this is the ID of an existing outcome

// Get by ID and culture. Will get the latest active version
IOutcomeDefinition outcome = manager.Get(outcomeId, new CultureInfo("da"));

// Get by ID and culture. Will get the latest version, including if the version is inactive
IOutcomeDefinition outcome = manager.Get(outcomeId, new CultureInfo("da"), true);

Retrieve an outcome by its alias

You can also retrieve an outcome by its alias:

RequestResponse
CultureInfo outcomeCulture = new CultureInfo("fr-fr");
var outcomeDefinitionByAlias = definitionManager.GetByAlias("My alias", outcomeCulture);

Update an existing outcome

To update an existing outcome definition, retrieve the outcome by ID, edit the outcome

RequestResponse
Guid outcomeId = Guid.NewGuid(); // Ensure this is the ID of an existing outcome

// Get by ID and culture. Will get the latest active version
IOutcomeDefinition outcome = manager.Get(outcomeId, new CultureInfo("da"));

// Make updates to outcome
outcome.Name = "Updated name";

// Save to update
manager.SaveAsync(outcome);

Retrieving all outcomes

The GetAll() method can be used to get all outcomes 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.

RequestResponse
    // Get All with defaults which will be first page, page size 20, latest active versions only
    ResultSet<DefinitionResult<IOutcomeDefinition>> outcomes = manager.GetAll(new CultureInfo("da"), new RetrievalParameters<IOutcomeDefinition, string>());

    // Get page 2
    ResultSet<DefinitionResult<IOutcomeDefinition>> page2Outcomes = manager.GetAll(new CultureInfo("da"), new RetrievalParameters<IOutcomeDefinition, string>(pageNumber: 2));

    // Include inactive versions
ResultSet<DefinitionResult<IOutcomeDefinition>> page1Outcomes = manager.GetAll(new CultureInfo("da"), new RetrievalParameters<IOutcomeDefinition, string>(), true);

To access the results, use the DataPage property of the result.

RequestResponse
IOutcomeDefinition outcome = page1Outcomes.DataPage.ElementAt(0);

The result also includes properties to expose the total number of definitions and the current page index and page size.

RequestResponse
long totalDefinitionCount = page1Outcomes.Total;
int pageNumber = page1Outcomes.PageNumber;
int pageSize = page1Outcomes.Count;

Do you have some feedback for us?

If you have suggestions for improving this article,