---
title: "成果"
slug: "outcomes"
abstract: ""
---
# 成果

アウトカムの定義はSitecore.Marketing.Definitions.Outcomes.OutcomeDefinitionManagerクラスによって管理されます。

> !注結果は専門的な出来事です。IOutcomeDefinitionIEventDefinitionを継承します。

## OutcomeDefinitionManagerへのアクセス

OutcomeDefinitionManagerはSitecore DIコンテナから利用可能です。クラスのコンストラクタに型DefinitionManagerBase<IOutcomeDefinition, OutcomeDefinitionRecord>のパラメータを含め、コンテナからクラスを引き出すことで、コンテナがインスタンスを解決するのが望ましいです。

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

コンテナを使ってクラスを構築できない場合は、サービスロケーターを使うことができます。このクラスはSitecore DIコンテナでも利用可能です:

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

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

## 結果の定義

結果はSitecore.Marketing.Definitions.Outcomes.Model名前空間の型を用いて定義されます。

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;

> !注IsMonetaryValueApplicable報告に使われます。契約の署名や約束など、意味のある金銭的価値のない結果が出ることは有効です。このような場合、IsMonetaryValueApplicableを偽に設定してください。
> 
> AdditionalRegistrationsAreIgnoredOutcomeManagerで使用され、現在は使用されていません。このプロパティはコードから削除してください。

### ライブイベント

IsLiveEventプロパティは基本EventDefinitionクラスの一部であり、マーケティングオートメーションがイベントをセッション終了時ではなく即時処理するかどうかを判断するために使用されます。[ライブイベント処理](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/marketing-automation-plan-and-activity-enrollment.html "Marketing Automation plan and activity enrollment")についてさらに詳しくはこちらをご覧ください。

## 結果を救う

結果を定義したら、定義マネージャーのSaveAsync() メソッドを呼び出すことで保存できます。

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);

また、セーブ中にSaveAsync()メソッドの2つ目のパラメータにtrueを渡すことで結果を有効化することも可能です。

manager.SaveAsync(outcome, true);

## 結果の発動

アウトカムは管理外で利用可能になる前に有効化しなければなりません。アウトカムは保存された際に、SaveAsync()メソッドのactivate(2つ目の)パラメータにtrue渡すことで有効化できます。

manager.SaveAsync(outcome, true);

また、ActivateAsync() メソッドを使ってセーブを呼ばずにアウトカムを有効化することも可能です。

manager.ActivateAsync(outcomeId);

ActivateAsync()法は結果のIDを取り、結果定義モデルを必要としません。

## 結果の削除

結果を削除するには、マネージャーのDelete() メソッドを使用します。個々の文化は定義から削除できず、定義全体のみ削除できます。メソッド呼び出しに提供される文化は、null(デフォルト値)またはCultureInfo.InvariantCultureのいずれかであるべきです。

manager.Delete(outcomeId);

## 結果を取得する

単一の結果は、マネージャのGet() メソッドのいずれかを用いてIDで取得できます。

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);

### 別名で結果を取得

また、[その別名](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/definition-aliases.html "Definition aliases")からも結果を取得することができます:

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

## 既存の成果を更新すること

既存の結果定義を更新するには、IDで結果を取得し、結果を編集します

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);

## すべての結果の取得

GetAll()メソッドはマネージャーからすべての結果を取得するために使用できます。定義が多数存在する場合があるため、このメソッドはページングをサポートしています。返される値は1ページ分の結果です。

// 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);

結果にアクセスするには、結果のDataPageプロパティを使いましょう。

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

その結果には、定義の総数や現在のページインデックス、ページサイズを公開するプロパティも含まれています。

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