> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Context

> Context グローバルオブジェクト — ルール実行中にDocument、field、カタログ レコード、および Skill Parameter にアクセスするためのプロパティとメソッド。

`Context` はグローバルオブジェクトで、処理中のDocument、その fields、および属するトランザクションのパラメーターにアクセスできます。ルールが成功したかどうかを示すには、[`CheckSucceeded`](#checksucceeded) を設定します。

<div id="usage">
  ## 使用法
</div>

ルールは `Context` を通じて field を読み取り、内容を確認したうえで、[`CheckSucceeded`](#checksucceeded) と [`ErrorMessage`](#errormessage) を設定して結果を報告します。たとえば、`Total` field が存在しない、または空の場合は、カスタムメッセージを設定してルールを失敗させます。

```javascript theme={null}
var field = Context.GetField("Total");

if (!field || !field.Value) {
  Context.CheckSucceeded = false;
  Context.ErrorMessage = "Total field is empty";
}
```

その他のパターン (数値比較、条件付き要件、テーブルの検証) については、[サンプルスクリプト](/ja/vantage/documentation/skill-designer/document/rule-verification/sample-scripts)を参照してください。

<div id="properties">
  ## プロパティ
</div>

<div id="checksucceeded">
  ### CheckSucceeded
</div>

**Type:** `bool` — **Access:** 読み取り/書き込み

ルールの条件が満たされているかどうかを示します。既定値は `true` です。条件が満たされていない場合は、`false` に設定します。この場合、オペレーターに表示される既定のエラーメッセージは `Error in the rule <rule_name>: <field_name>` です。メッセージをカスタマイズするには、`ErrorMessage` プロパティを設定します。

<Note>
  エラーが生成されるのは、スクリプトで `CheckSucceeded` を `false` に設定した場合のみです。スクリプトでこれを明示的に設定しない限り、ルールの条件が満たされていなくてもエラーは表示されません。
</Note>

<div id="currentfield">
  ### CurrentField
</div>

**Type:** [Field](/ja/vantage/documentation/skill-designer/document/rule-verification/field) — **Access:** 読み取り専用

ルールでチェックされる field です。繰り返しルール内の繰り返し field の場合、これは現在の呼び出しでチェック対象となっている特定のインスタンスを指します。ルールがDocument 全体を参照している場合は、`null` を返します。

<div id="document">
  ### Document
</div>

**Type:** [Document](/ja/vantage/documentation/skill-designer/document/rule-verification/document) — **Access:** 読み取り専用

ルールが実行される対象のDocumentです。

<div id="errormessage">
  ### ErrorMessage
</div>

**Type:** `string` — **Access:** 読み取り/書き込み

スクリプトで `CheckSucceeded` を `false` に設定したときに表示されるカスタムメッセージです。設定されていない場合、既定のメッセージは `Error in the rule <rule_name>: <field_name>` です。

<div id="transaction">
  ### Transaction
</div>

**Type:** [Transaction](/ja/vantage/documentation/skill-designer/document/rule-verification/transaction) — **Access:** 読み取り専用

現在のトランザクションです。

<div id="methods">
  ## メソッド
</div>

<Note>
  スクリプトは、ルールの設定時に読み取り用として一覧に含まれている fields のみを読み取り、編集可能として一覧に含まれている fields にのみ書き込むことができます。その他の field を参照すると、アクセス エラー (`Attempt to read data from inaccessible field` または `Attempt to write data to read-only field`) が発生し、ルールは失敗します。[ビジネス ルールの自動化](/ja/vantage/documentation/skill-designer/document/rule-verification/business-rules-automation)を参照してください。
</Note>

<div id="getfield">
  ### GetField
</div>

```javascript theme={null}
Field GetField(string fieldName);
```

名前または識別子で [`Field`](/ja/vantage/documentation/skill-designer/document/rule-verification/field)を取得します。その名前のfieldが存在しない場合は `null` を返します。

グループ内のfieldを指定するには、[フルパス](/ja/vantage/documentation/skill-designer/document/rule-verification/field#fullname)を使用します。たとえば、`BusinessUnit/Address` です。

繰り返しルールで使用すると、`GetField` は処理済みの各fieldインスタンスを順番に返します。そうでない場合は、繰り返しfieldの最初のインスタンスを返します。

<Warning>
  field名は変数ではなく、stringリテラルとして渡してください。スクリプトのプリプロセッサは、実行前にリテラル名をfieldの識別子に置き換えます。変数は処理されません。
</Warning>

<div id="getfields">
  ### GetFields
</div>

```javascript theme={null}
Field[] GetFields(string fieldName);
```

指定した名前のすべての[`Field`](/ja/vantage/documentation/skill-designer/document/rule-verification/field)オブジェクトを返します。これは、テーブルの列内のすべてのセルを含め、繰り返しfieldの各インスタンスを反復処理する場合に便利です。その名前のfieldが存在しない場合は`null`を返します。

<Warning>
  `GetField`と同じプリプロセッサの制約があります。変数ではなく、文字列リテラルを渡してください。
</Warning>

<div id="getcatalogrecord">
  ### GetCatalogRecord
</div>

```javascript theme={null}
Record GetCatalogRecord(string catalogId, string externalId);
```

[`Record`](/ja/vantage/documentation/skill-designer/document/rule-verification/record) をデータ カタログ (外部データベース) から取得します。このメソッドを使用して、ドキュメントのfield値をカタログのfield値と比較します。

<Note>
  カタログにレコード識別子 (たとえば、ベンダー識別子) が設定されている場合にのみ利用できます。
</Note>

<div id="skillparameter">
  ### SkillParameter
</div>

```javascript theme={null}
SkillParameter SkillParameter(string ParameterName);
```

名前を指定して [`SkillParameter`](/ja/vantage/documentation/skill-designer/document/rule-verification/skill-parameter) を取得します。値は、返されたオブジェクトの `Value` プロパティから読み取ります。たとえば、`Context.SkillParameter("Threshold").Value` です。

<Note>
  Document skill に少なくとも 1 つの Parameter がある場合にのみ使用できます。
</Note>

<div id="related-topics">
  ## 関連トピック
</div>

* [オブジェクト モデル](/ja/vantage/documentation/skill-designer/document/rule-verification/object-model)
* [ビジネス ルールの自動化](/ja/vantage/documentation/skill-designer/document/rule-verification/business-rules-automation)
* [Field](/ja/vantage/documentation/skill-designer/document/rule-verification/field)
* [サンプルスクリプト](/ja/vantage/documentation/skill-designer/document/rule-verification/sample-scripts)
