取引プロモーション管理の変換エンジンワークフロー
ワークフローには、入力 JSON から出力構造への変換を適用する APEX コール可能クラスが含まれています。
ビジネスオブジェクト API ワークフロールールでは、Entities の概念を使用して、データ入力 (入力ペイロード) と出力 (生成されたオブジェクトまたはレコード) の両方のレコードが識別されます。エンジンでサポートされるエンティティは、ビジネスオブジェクト API エンティティオブジェクトで確認できます。管理パッケージで提供されるエンティティを次に示します。
| エンティティ名 | 場所 | 説明 |
|---|---|---|
| Promotion | 入力 | 入力プロモーションを表します。オブジェクトの属性は、このエンティティを使用するワークフロールールで定義されます。 |
| Tactic | 入力 | 入力戦略を表します。オブジェクトの属性は、このエンティティを使用するワークフロールールで定義されます。 |
| ManualInputs | 入力 | 手動入力配列を表します。オブジェクトの属性は、このエンティティを使用するワークフロールールで定義されます。 |
| ProductFilter | 入力 | 商品検索条件構造を表します。オブジェクトの属性は、このエンティティを使用するワークフロールールで定義されます。 |
| TPM_Promotion | 出力 | すべてのプロモーションデータを含む TPM_Promotion インスタンスを表します。 |
| TPM_Promotion.Promotion | 出力 | すべてのプロモーション SObject データを含む TPM_Promotion.Record インスタンスを表します。SObject 項目は、ドット表記と共に使用できます。 |
| TPM_Promotion.Tactic | 出力 | すべての戦略 SObject データを含む TPM_Promotion.TacticRecord インスタンスを表します。SObject 項目は、ドット表記と共に使用できます。 |
| TPM_Promotion.Attachment | 出力 | すべてのプロモーション添付ファイル SObject データを含む TPM_Promotion.Record インスタンスを表します。SObject 項目は、ドット表記と共に使用できます。 |
| TPM_Promotion.AttachmentLink | 出力 | すべてのプロモーション添付ファイルリンク SObject データを含む TPM_Promotion.Record インスタンスを表します。SObject 項目は、ドット表記と共に使用できます。 |
| TPM_Promotion.ProductFilter | 出力 | すべてのプロモーション商品検索条件の情報を含む TPM_ProductFilter インスタンスを表します。 |
| TPM_Promotion.ProductShare | 出力 | すべてのプロモーション商品共有 SObject データを含む TPM_Promotion.Record インスタンスを表します。SObject 項目は、ドット表記と共に使用できます。 |
| TPM_Promotion.TacticConditionCreationDefinition | 出力 | すべての戦略条件作成定義 SObject データを含む TPM_Promotion.Record インスタンスを表します。SObject 項目は、ドット表記と共に使用できます。 |
| TPM_Promotion.TacticFund | 出力 | すべての戦略資金 SObject データを含む TPM_Promotion.Record インスタンスを表します。SObject 項目は、ドット表記と共に使用できます。 |
| TPM_Promotion.TacticProductFilter | 出力 | すべての戦略商品検索条件の情報を含む TPM_ProductFilter インスタンスを表します。 |
| CustomState | 出力 | 保存中にプロモーション保存プロセスに渡される汎用オブジェクトを表します。 |
- ワークフローステップ SObject
- ワークフローステップは、Workflow Step SObject で定義されます。各ステップでは、次の一連の属性が必要です。
表 2. ワークフローステップのパラメータ オブジェクト 説明 必須か省略可能 Name ビジネスルールの名前。 必須 Entity ルールを適用する必要がある入力のエンティティ。 省略可能 Method コール可能なクラスに渡されるアクションメソッド。 省略可能 Classname 変換を実装している APEX コール可能クラスの名前。 必須 Description ルールで実行される内容の概要。 省略可能 - 入力構造レコード
- すべてのルールには、ルールで要求される入力を反映した入力構造レコードのリストが必要です。各レコードには、次の情報が必要です。
表 3. 入力構造レコード オブジェクト 説明 Path ルールが値を読み取る入力 JSON のパス。 可能な値は次のとおりです。- .TacticTemplate
- .Categories
Required プロパティが必須であるか、省略可能であるかを示す Boolean。 RecordType プロパティで要求される入力の種別。 可能な値は次のとおりです。- Object
- Array
- String
- number
- Boolean
- Maximum and Minimum (Numbers)
- Pattern (String)
- 適用される変換ルール
-
Applied Transformation Rules は、Transformation Configuration Record で設定されます。次の表は、更新が必要なレコード検索条件に関する情報を示しています。
表 4. 適用される変換レコード項目 オブジェクト 説明 Transformation Rule 適用される変換ルール。 Enabled ルールが適用されるかどうかを示します。 Sort ルールは昇順で実行されます (連動関係の作成が可能)。
Transformation Rules APEX クラスは、次の属性を持つコンテキストオブジェクトを受け取ります。
1// Common to all steps.
2String txId: TransactionId of the process
3String salesOrg: Sales organization passed to the execution.
4Object input: Whole Input Object
5Object output: Whole Output Object
6
7// Step specific
8SObject workflowStepRecord: Workflow Step Record.
9
10// Entity specific
11String inputPath: Path of the current input in the main input object.
12String inputEntityPath: A list of the names of the parent input entities ordered based on the deepness level. (i.e. Promotion/Tactic/TacticBrand).
13Object currentInput: Current block of the input object being processed.
14List<Object> parentInputs: A list of the parent Input Entities for this step. Each entry on the list will be the input Entity. Has the same number of elements as the inputEntityPath. (i.e. [ 0 ] → Promotion, [ 1 ] → Tactic, [ 2 ] → TacticBrand)
15
16String outputPath: Path of the current output in the main output object.
17String outputEntityPath: A list of the names of the parent output entities ordered based on the deepness level. (i.e. BOPromotion/LOTactic).
18Object currentOutput: Output object where the rule is expected to set the attributes. Rules are expected to set this object into the proper place of the parent.
19List<Object> parentOutputs: A list of the parent Output Entities for this step. Each entry on the list will be the output Object for the Entity. Has the same number of elements as the outputEntityPath. (i.e. [ 0 ] → BOPromotion, [ 1 ] → LOTactic)例
指定された新しい値を使用して Tactic Comment (戦略コメント) 項目を更新する完全なワークフローを新規に作成します。
- [Business Object APIs (ビジネスオブジェクト API)] タブに移動して、セールス組織 0001 の Promotion エントリに移動します。存在しない場合は、それらの属性を持つレコードを作成します。
- BO API の出力エンティティを設定します。BO API の出力エンティティでは、API で処理されるオブジェクトの種別を定義します。Output Entities 関連リストで、次のエンティティが表示されることを確認します。関連リストにない場合は追加します。
- TPM_Promotion (メインのプロモーションオブジェクトラッパー)
- TPM_Promotion.Tactic (戦略レコード)
- TPM_Promotion.Promotion (プロモーションレコード)
- ワークフロータブで、次の属性を持つワークフローを作成します。
- 名前: updateTacticComments
- 説明: 入力パラメータを使用して Tactic Comment (戦略コメント) を更新します。
- 新しいワークフローレコードに移動します。
- 入力レコードを出力レコードに対応付ける方法を設定します。これを行うには、「入力エンティティおよび対応付け」関連リストにエントリを追加します。関連リストで次のレコードを作成します。
レコード 1
- ビジネスオブジェクト API エンティティ: Promotion
- 出力エンティティ: TPM_Promotion.Promotion
- 入力対応付け項目: Id
- 出力対応付け項目: Id、cgcloud__ExternalId__c
レコード 2
- ビジネスオブジェクト API エンティティ: Tactic
- 出力エンティティ: TPM_Promotion.Tactic
- 入力対応付け項目: Id
- 出力対応付け項目: Id、cgcloud__ExternalId__c
- ワークフローにステップを追加します。必要なプロモーションデータをすべて読み込むには、管理パッケージで提供されるワークフローステップを再利用します。ワークフローステップ関連リストで、次のレコードを作成します。
レコード 1
- ビジネスオブジェクト API ワークフローステップ: loadPromotionDefaults(update)2
- 有効化: チェック済み
- 並び替え: 10
レコード 2
- ビジネスオブジェクト API ワークフローステップ: loadTacticDefaults(update)2
- 有効化: チェック済み
- 並び替え: 20
- [ワークフロー] ヘッダーの [スキーマを参照] ボタンをクリックして、この API の入力ペイロード構造を確認します。スキーマは次のようになります。
1{ 2 "required" : [ "Id" ], // Promotion requires an Id because of the Promotion workflow step 3 "properties" : { 4 "Tactics" : { 5 "items" : { 6 "required" : [ "Id" ], // Tactic requires an Id because of the Tactic workflow step 7 "properties" : { 8 "TacticTemplate" : { 9 "pattern" : null, 10 "minLength" : null, 11 "maxLength" : 40, 12 "type" : "string" 13 }, 14 "Id" : { 15 "pattern" : null, 16 "minLength" : null, 17 "maxLength" : 40, 18 "type" : "string" 19 } 20 }, 21 "additionalProperties" : false, 22 "type" : "object" 23 }, 24 "type" : "array" 25 }, 26 "PromotionTemplate" : { 27 "pattern" : null, 28 "minLength" : null, 29 "maxLength" : 40, 30 "type" : "string" 31 }, 32 "Id" : { 33 "pattern" : null, 34 "minLength" : null, 35 "maxLength" : 40, 36 "type" : "string" 37 } 38 }, 39 "additionalProperties" : false, 40 "type" : "object" 41} - カスタム動作を追加します。別のワークフローステップを追加するには、入力の入力属性を SObject 項目の Comment__c にコピーする APEX クラスを作成します。組織で次の APEX クラスを作成します。
1global with sharing class SetCommentValue implements System.Callable { 2 public class SetCommentValueException extends Exception {} 3 /** 4 * This Sample Business Rule copies the value from the MyComment input attribute, 5 * into the Output Comment__c field 6 */ 7 public static Object call(String method, Map<String, Object> context) { 8 // We use the context to extract variables 9 // The type of the output object is defined by it's output entity in the mapping. 10 cgcloud.TPM_Promotion.TacticRecord tactic = (cgcloud.TPM_Promotion.TacticRecord) 11 context.get('currentOutput'); 12 // For input entities, it's type is always Map<String, Object> 13 Map<String, Object> input = (Map<String, Object>) context.get('currentInput'); 14 15 // Set the value to the record 16 cgcloud__Tactic__c myRecord = (cgcloud__Tactic__c) tactic.getRecord(); 17 18 myRecord.Comment__c = input.get('MyComment') != null 19 ? String.valueOf(input.get('MyComment')) 20 : ''; 21 22 // After setting the value, we can return. The promotion and its 23 // related records will be saved 24 25 // If any exception is thrown, no data is committed 26 return null; 27 } 28} - BO API ワークフローステップレコードを作成します。[Business Object API Workflow Steps (ビジネスオブジェクト API ワークフローステップ)] タブに移動して、新しいレコードを作成します。
- ビジネスオブジェクト API ワークフローステップ名: SetCommentValue
- クラス名: SetCommentValue (APEX クラスの名前)
- 説明: 入力属性からの Tactic (戦略) の Comment Value (コメント値) を設定します。
- メソッド: test (メソッドはコール可能なクラスに渡されます。この方法により、さまざまなメソッドを使用して、同じクラスが複数の動作を実装できます。)
- エンティティ: Tactic (このステップを各入力戦略で適用したいため)。
- セールス組織: 0001
- ステップで必要な入力構造を定義します。ワークフローステップのステップ入力構造関連リストのレコードを作成します。ステップ入力構造の属性は、入力に必要なスキーマを決定するために使用されます ([スキーマを参照] ボタン)。入力がスキーマに一致しない場合は、エラーが表示されます。
- レコードタイプ: String
- 説明: 新しいコメント属性の値
- パス: .MyComment
- 必須: チェックしない
- 最大文字数: 80
- ワークフローステップをワークフローレコードに追加します。
- ビジネスオブジェクト API ワークフローステップ: SetCommentValue
- 有効化: チェック済み
- 並び替え: 30
- [スキーマを参照] をクリックします。スキーマの構造は、次のようになります。
1{ 2 "required" : [ "Id" ], 3 "properties" : { 4 "Tactics" : { 5 "items" : { 6 "required" : [ "Id" ], 7 "properties" : { 8 "MyComment" : { 9 "pattern" : null, 10 "minLength" : null, 11 "maxLength" : 80, 12 "type" : "string" 13 }, 14 "TacticTemplate" : { 15 "pattern" : null, 16 "minLength" : null, 17 "maxLength" : 40, 18 "type" : "string" 19 }, 20 "Id" : { 21 "pattern" : null, 22 "minLength" : null, 23 "maxLength" : 40, 24 "type" : "string" 25 } 26 }, 27 "additionalProperties" : false, 28 "type" : "object" 29 }, 30 "type" : "array" 31 }, 32 "PromotionTemplate" : { 33 "pattern" : null, 34 "minLength" : null, 35 "maxLength" : 40, 36 "type" : "string" 37 }, 38 "Id" : { 39 "pattern" : null, 40 "minLength" : null, 41 "maxLength" : 40, 42 "type" : "string" 43 } 44 }, 45 "additionalProperties" : false, 46 "type" : "object" 47} - プロモーション BO API エンドポイントに対して REST コールを実行し、必要なパラメータを渡して、API をテストします。
1POST /services/apexrest/cgcloud/promotions/ingest 2 3{ 4 "workflow": "updateTacticComments", // Name of your workflow 5 "salesOrg": "0001", 6 "promotions": [ 7 { 8 "Id": "a2VTC0000001lJR2AY", // A promotion in the system 9 "Tactics": [ 10 { 11 "Id": "a36TC0000000XYfYAM", // It's tactics 12 "MyComment": "Comment 1 - updated" 13 }, 14 { 15 "Id": "a36TC0000000XYgYAM", 16 "MyComment": "Comment 2 - updated" 17 } 18 ] 19 } 20 ] 21} - 返された importId で要求を参照して、[Business Object API Transaction Logs (ビジネスオ��ジェクト API トランザクションログ)] タブから実行状況を追跡します。