Order Management拡張からのWebサービスのコール
デフォルト・ロジックまたは検証ロジックを実行する前に、オーダー管理拡張を使用して、Order Managementの外部にあるソースからデータを取得します。
拡張コードでServiceInvokerを使用して、webサービスをコールし、データを取得します。 ServiceInvokerは、コンテキスト・オブジェクトから使用できます。 ExecutionContextメソッドを使用します。
次のような拡張例を作成します:
-
条件を満たす品目を含むオーダー明細の営業担当に販売実績を割り当てます。
-
webサービスのコール時に購買オーダー番号および品目番号を参照して、営業担当の名前および割当する販売実績率を取得できるようにします。
-
webサービス・レスポンスから営業担当名およびパーセント割当を抽出し、オーダー明細から取得する販売実績行セットに新しい行を作成します。
ステップの概要
-
webサービスを登録します。
-
webサービスを呼び出します。
-
対象の品目を決定します。
このトピックではサンプル値を使用します。 ビジネス要件によっては、別の値が必要になる場合があります。
Webサービスの登録
-
「コネクタ詳細の管理」ページに移動し、値を設定します。
属性
値
起動モード
同期サービス
同期サービスは、オーダー管理拡張とともに使用する必要があります。
詳細は、「オーダー管理と履行システム間のコネクタ詳細の管理」を参照してください。
-
「オーダー管理拡張の管理」ページに移動し、新しい拡張を作成します。
-
コールを設定します。
コード
説明
def lines = header.getAttribute("Lines");
オーダー明細の行セットを取得します。
while( lines.hasNext() )
処理する必要がある明細がさらに存在するかどうかを決定します。
def line = lines.next();
def itemNumber = line.getAttribute("ProductNumber");
明細で指定する品目番号を取得します。
if( itemOfInterest(itemNumber) )
品目番号が条件を満たすかどうかを決定します。
allocateSalesCredits(line);
この明細に販売実績を割り当てるメソッドをコールします。
Webサービスの呼出し
販売実績割当を取得できるようにwebサービスを呼び出すコードを追加します。
コード |
説明 |
---|---|
|
webサービスの呼出しに使用するハンドルを取得します。 |
|
オーダー・ヘッダーから顧客の購買オーダー番号属性の値を取得します。 |
|
ペイロードを準備できるように文字列を連結します。 オプションとして、XML APIを使用して文字列を連結することもできます。 |
|
webサービスのインタフェース名およびリクエスト・ペイロードを使用して、Webサービスをコールします。 「外部インタフェースのWebサービス詳細の管理」ページのコネクタ名属性でインタフェース名を指定する必要があります。 この例では、コネクタ名としてSalesCreditAllocationServiceを指定します。 Oracle内部webサービスまたはOracleホストを使用するコネクタを登録しないでください。 詳細は、「Order Managementを履行システムに接続」を参照してください。 |
|
レスポンス・ペイロードから営業担当名を抽出します。 |
|
レスポンス・ペイロードからパーセント割当てを抽出します。 |
|
現在の明細から販売実績の行セットを取得します。 |
|
販売実績行を作成します。 |
|
営業担当属性の値を設定します。 |
|
パーセント配賦属性の値を設定します。 |
|
販売実績タイプを設定します。 この例では、1がRevenue creditsと等しいとします。 |
|
新しい行を行セットに挿入します。 |
コードはパラメータを使用します。
-
param line
. 販売実績を割り当てる明細です。 -
param itemNumber
. 明細に指定する品目の番号。
関心品目の決定
ブール値を返すコードを追加して、webサービスが送信した品目に関心があるかどうかを示します。
コード |
説明 |
---|---|
|
簡潔にするために、この例では、このメソッドの実装方法に関する詳細は含まれていません。 使用するロジックは、ビジネス要件に固有です。 |
「条件」の場合
|
「条件」は、記述するコードです。 品目番号が対象かどうかを決定します。 |
コード全体
この例のコードを次に示します。
//get the lines row set.
def lines = header.getAttribute("Lines");
//if more lines exist.
while( lines.hasNext() ) {
def line = lines.next();
//then get the item number that the line specifies.
def itemNumber = line.getAttribute("ProductNumber");
//determine whether the item number satisfies the condition.
if( itemOfInterest(itemNumber) ) {
//call method to allocate sales credits for this line.
allocateSalesCredits(line);
}
}
/**
* Call a web service that gets sales credit allocation for the order line.
* @param line identifies the line where you allocate sales credit.
* @param itemNumber is the number of the item that the line specifies.
*/
void allocateSalesCredits(def line, String itemNumber) {
//get a handle for the method that calls the web service.
def serviceInvoker = context.getServiceInvoker();
//get the customer attribute for the purchase order number from the order header.
def poNumber = header.getAttribute("CustomerPONumber");
String payLoad = "<ns1:GetSalesCreditAllocation
//concatenate the strings to prepare the payload.
xmlns:ns1=\"http://your.address/SalesCreditWS/\">" +
//As an alternative, you can also use this code:
"<ns1:poNumber>" + poNumber + "</ns1:poNumber>" +
//XML APIs
"<ns1:itemNumber>" + itemNumber + "</ns1:itemNumber>" +
"</ns1:GetSalesCreditAllocation>";
def responseBody =
//use the web service name and the constructed payload to call the service.
serviceInvoker.invokeSoapService("SalesCreditAllocationService",
payLoad).getSoapBody();
//get the salesperson name from the web service response.
def salesPerson = //;
//get the percent allocation from the service response.
def percent = //
//get the row set for the sales credit for the current line.
def salesCredits = line.getAttribute("SalesCredits");
//create a new row for the sales credit.
def salesCredit = salesCredits.createRow();
//set the salesperson attribute.
sc.setAttribute("Salesperson", salesPerson);
//set the percent allocation attribute.
sc.setAttribute("Percent", new BigDecimal(percent));
//set the sales credit type. This code assumes your implementation uses the value 1 for revenue credits.
sc.setAttribute("SalesCreditTypeCode", 1L);
//set a unique identifier in case more than one SalesCredit exists. For example, 5768342869.
salesperson.setAttribute("SourceTransactionSalesCreditIdentifier',5768342869);
//insert the new row in the rowset.
salesCredits.insertRow(salesCredit);
}
/**
*Return a boolean that indicates whether the item is of interest.
*/
boolean itemOfInterest(String itemNumber) {
//For brevity, and to keep focus on calling the web service,
//this example does not include details about how to implement this method.
//The logic you use is specific to your business process.
//Decide whether the item number is of interest. Pseudocode:
// if (some condition)
return true;
// else
// return false
}
これはコメントなしで同じコードです。
def lines = header.getAttribute("Lines");
while( lines.hasNext() ) {
def line = lines.next();
def itemNumber = line.getAttribute("ProductNumber");
if( itemOfInterest(itemNumber) ) {
allocateSalesCredits(line);
}
}
void allocateSalesCredits(def line, String itemNumber) {
def serviceInvoker = context.getServiceInvoker();
def poNumber = header.getAttribute("CustomerPONumber");
String payLoad = "<ns1:GetSalesCreditAllocation
xmlns:ns1=\"http://your.address/SalesCreditWS/\">" +
serviceInvoker.invokeSoapService("SalesCreditAllocationService",
payLoad).getSoapBody();
def salesPerson = //;
def percent = //
def salesCredits = line.getAttribute("SalesCredits");
def salesCredit = salesCredits.createRow();
sc.setAttribute("Salesperson", salesPerson);
sc.setAttribute("Percent", new BigDecimal(percent));
sc.setAttribute("SalesCreditTypeCode", 1L);
salesperson.setAttribute("SourceTransactionSalesCreditIdentifier',5768342869);
salesCredits.insertRow(salesCredit);
}
boolean itemOfInterest(String itemNumber) {
//implement this method.
//Decide whether the item number is of interest. Pseudocode:
// if (some condition)
return true;
// else
// return false
}