機械翻訳について

拡張機能を使用したOracle Applicationsからのデータの取得

コンテキスト・オブジェクトでAPIをコールするオーダー管理拡張を記述し、表に対して問合せを実行し、表に含まれるパブリック・ビュー・オブジェクトにアクセスします。

Oracle Applicationsにデプロイした場合、Oracleデータベースにプログラムでアクセスすることはできません。 PL/I (プログラミング言語1)、SQL (構造化問合せ言語)またはJDBC (Java Database Connectivity)を使用して、他のアプリケーション表のデータにアクセスすることはできません。 代わりに拡張を記述してください。

次に、パブリック・ビュー・オブジェクトにアクセスする拡張機能の例を示します。

コード

説明

def itemPVO = context.getViewObject("oracle.apps.scm.productModel.items.publicView.ItemPVO");

品目のパブリック・ビュー・オブジェクトのインスタンスを作成します。 パブリック・ビュー・オブジェクトの名前全体を指定する必要があります。

このコードは、各パブリック・ビュー・オブジェクトを行イテレータとして使用するため、RowIteratorインタフェースのメソッドも各パブリック・ビュー・オブジェクトで使用できます。 RowSetIteratorメソッドを使用して、ビュー・オブジェクト問合せが返す行を取得するメソッドにアクセスし、パブリック・ビュー・オブジェクトの行セットにナビゲートできます。 ViewObjectメソッドを確認します。 詳細は、「Order Managementの拡張機能で使用できるメソッド」を参照してください。

def item = itemPVO.first();

1つ目の品目にアクセスします。

一般的に使用するパブリック・ビュー・オブジェクトは次のとおりです。

データ

ビュー・オブジェクト名

販売オーダー

HeaderPVO

FulfillLinePVO

項目

ItemPVO

ItemCategoryPVO

Customer

PartyPVO

PartySitePVO

LocationPVO

顧客アカウント

CustomerAccountPVO

CustomerAccountSitePVO

CustomerAccountSiteUsePVO

売掛/未収金

TransactionTypePVO

注意: REST APIを使用して、ビジネス・オブジェクトを介してデータにアクセスすることをお薦めします。 ただし、なんらかの理由でREST APIを使用できない場合は、かわりにパブリック・ビュー・オブジェクトを使用できますが、Oracleでサポートされているパブリック・ビュー・オブジェクトのみを使用する必要があります。 それらの完全なリストおよびそれらに含まれる属性を取得するには、「Oracle Applications Cloudのパブリック・ビュー・オブジェクト(ドキュメントID 2386411.1)」からXLSファイルをダウンロードします。

ビュー基準オブジェクトを使用した結果のフィルタ

前述の例はデモンストレーションのみを目的としています。 項目表から任意の項目を取得するため、実際に使用するには単純すぎます。 基準に一致する項目または項目のセットを問い合せる必要がある可能性が高くなります。 SQLをサポートするには、条件に一致する行のみを選択するWHERE句を拡張で指定する必要があります。 この目的には、ViewCriteriaオブジェクトを使用します。

オーダー管理拡張では、これらのオブジェクトからデータを取得する前に、フィルタ・ロジックをパブリック・ビュー・オブジェクトに追加するビュー基準オブジェクトを作成できます。 「ビュー基準オブジェクト」は、プログラムで作成してビュー・オブジェクトに適用するフィルタです。 オーダー管理では、拡張でパブリック・ビュー・オブジェクトで定義した問合せが実行されると、これらの各フィルタがWHERE句に変換されます。

「ビュー基準行オブジェクト」を使用して、ビュー基準オブジェクトを作成します。 ビュー基準オブジェクトには、WHERE句の一部になる属性名と属性値が含まれます。

この例では、次の拡張を作成します:

  • ビュー基準を作成し、それを使用してパブリック・ビュー・オブジェクトを問い合せます。

  • 品目IDおよび在庫組織IDに従って、品目の品目マスターを問い合せます。

  • 品目のHazardousMaterialFlag属性を調べます。

  • HazardousMaterialFlag属性によって品目に危険のフラグが付けられると、拡張によって出荷指示フレックスフィールド・コンテキスト・セグメントが設定され、品目に危険な処理が必要であることが示されます。

このトピックではサンプル値を使用します。 ビジネス要件によっては、別の値が必要になる場合があります。

ビュー基準オブジェクトを使用して結果をフィルタします:

  1. 品目を取得します。

    コード

    説明

    def lines = header.getAttribute("Lines");

    オーダー明細の行セットを取得します。

    while( lines.hasNext() ) {

    より多くのオーダー明細を処理する必要があるかどうかを決定します。

    def line = lines.next();

    次の行を取得し、変数行に割り当てます。

    def inventoryItemId = line.getAttribute("ProductIdentifier");

    オーダー入力スペシャリストが選択したオーダー明細から品目の在庫品目IDを取得します。

    def orgId = line.getAttribute("InventoryOrganizationIdentifier");

    オーダー入力スペシャリストが選択したオーダー明細から品目の組織を取得します。

    def item = getItem(inventoryItemId, orgId);

    品目を取得します。 品目IDと組織IDを使用して、getItemメソッドをコールします。

    String hazardous = item.getAttribute("HazardousMaterialFlag");

    品目からHazardousMaterialFlag属性を取得します。

    if( "Y".equals(hazardous) ) {

    HazardousMaterialFlagが品目に危険のフラグを設定するかどうかを決定します。

    def packShipInstruction = line. getOrCreateContextRow("PackShipInstruction");

    PackShipInstructionという拡張可能フレックスフィールド・コンテキストの行を取得します。

    packShipInstruction.setAttribute("_ShippingInstruction", "Hazardous Handling Required.");

    出荷指示コンテキスト・セグメントを設定します。

  2. パブリック・ビュー・オブジェクトを定義します。

    コード

    説明

    Object getItem(Long itemId, Long orgId) {

    def itemPVO = context.getViewObject("oracle.apps.

    scm.productModel.items.publicView.ItemPVO");

    品目のパブリック・ビュー・オブジェクトのインスタンスを作成します。

    def vc = itemPVO.createViewCriteria();

    ビュー基準オブジェクトを作成します。

    def vcrow = vc.createViewCriteriaRow();

    ビュー基準行を作成します。

    vcrow.setAttribute("InventoryItemId", itemId);

    在庫品目属性をフィルタ条件に含めることができるように設定し、この属性との比較に使用する値を設定します。

    vcrow.setAttribute("OrganizationId", orgId);

    組織属性をフィルタ条件に含めることができるように設定し、この属性との比較に使用する値を設定します。

    def rowset = itemPVO.findByViewCriteria(vc, -1);

    パブリック・ビュー・オブジェクトの問合せ時に行をフィルタするビュー基準を定義します。

    def item = rowset.first();

    条件を満たす最初の品目行を取得します。

    このコードでは、次のパラメータを使用します:

    • param itemId. 品目を識別する在庫品目ID。

    • param orgId. 品目を所有する組織を識別する在庫組織ID。

コメントなしのコード

この例のコード全体をコメントなしで次に示します。

def lines = header.getAttribute("Lines");                                                             
while( lines.hasNext() ) {                                                                            
  def line = lines.next();                                                                            
  def inventoryItemId = line.getAttribute("ProductIdentifier");                                       
  def orgId = line.getAttribute("InventoryOrganizationIdentifier");                                   
  def item = getItem(inventoryItemId, orgId);                                                         
  String hazardous = item.getAttribute("HazardousMaterialFlag");                                      
  if( "Y".equals(hazardous) ) {                                                                       
def packShipInstruction = line. getOrCreateContextRow("PackShipInstruction");                     
packShipInstruction.setAttribute("_ShippingInstruction", "Hazardous Handling Required.");         
  } 
}

Object getItem(Long itemId, Long orgId) {
def itemPVO = context.getViewObject("oracle.apps.scm.productModel.items.publicView.ItemPVO");        
  def vc = itemPVO.createViewCriteria();                                                               
  def vcrow = vc.createViewCriteriaRow();                                                              
  vcrow.setAttribute("InventoryItemId", itemId);                                                       
  vcrow.setAttribute("OrganizationId", orgId);                                                         
  def rowset = itemPVO.findByViewCriteria(vc, -1);                                                     
  def item = rowset.first();                                                                           
  return item;
}

この例では、与信チェックを実行するwebサービスをコールします。

import oracle.apps.scm.doo.common.extensions.ValidationException;
import oracle.apps.scm.doo.common.extensions.Message;

def poNumber = header.getAttribute("CustomerPONumber");

if (poNumber != "PMC TEST") return;

//get attribute to populate in the payload
String customer = header.getAttribute("BillToCustomerName");
Long accountId = header.getAttribute("BillToCustomerIdentifier");
BigDecimal amount = new BigDecimal(1000);

//prepare the payload
String payLoad = "<ns1:creditChecking xmlns:ns1=\"http://xmlns.oracle.com/apps/financials/receivables/creditManagement/creditChecking/creditCheckingService/types/\">" +
    "<ns1:request xmlns:ns2=\"http://xmlns.oracle.com/apps/financials/receivables/creditManagement/creditChecking/creditCheckingService/\">" +
    "<ns2:CustomerName>" + customer + "</ns2:CustomerName>" +
    "<ns2:CustomerAccountNumber>" + accountId + "</ns2:CustomerAccountNumber>" +
    "<ns2:RequestType>Authorization</ns2:RequestType>" +
    "<ns2:PriceType>ONE_TIME</ns2:PriceType>" +
    "<ns2:RecurrencePeriod></ns2:RecurrencePeriod>" +
    "<ns2:RequestAuthorizationAmount currencyCode=\"USD\">" + amount + "</ns2:RequestAuthorizationAmount>" +
    "<ns2:RequestAuthorizationCurrency>USD</ns2:RequestAuthorizationCurrency>" +
    "<ns2:ExistingAuthorizationNumber></ns2:ExistingAuthorizationNumber>" +
    "<ns2:Requestor>ar_super_user</ns2:Requestor>" +
    "</ns1:request>" +
    "</ns1:creditChecking>";

//Use the CreditCheckService web service connector to call the Check Credit service. Use the Manage External Interface Web Service Details task to set up the connector. This is a secured service,
//so we're using a message protection policy. We use the https URL of the service to register it.
def response = context.invokeSoapService("CreditCheckService", payLoad);

//Print a debug message. Append the entire response to the shipping instructions attribute.
//To avoid performance problems, you must comment out all debug statements in your production environment.
debug(response.getSoapBody().getTextContent());

//The response XML that the Credit Check service sends contains an element named Response. A YES value in the response means credit check passed. So, we extract the contents of the Response tag. The following XML API returns all tags
//that include the name Response in a NodeList element. We are expecting only one element in our XML response.
def nodeList = response.getSoapBody().getElementsByTagNameNS("*", "Response");

//Print out the lenght of the node list.
debug(nodeList.getLength());

//Get the first element that contains the name Response. We are expecting only one response. Then get its text content
String ccResponse = nodeList.item(0).getTextContent();

debug(ccResponse);

//Determine whether credit check passed.
if (ccResponse != 'YES') {
    //Credit check failed, so we a warning validation exception.
    throw new ValidationException(new Message(Message.MessageType.WARNING, "Credit check failed."));
} else {
    //Credit check passed.
    //Write the credit check response in an extensible flexfield.
    def psiContext = header.getOrCreateContextRow("ComplianceDetails");
    psiContext.setAttribute("_ComplianceInfo", ccResponse);
}

/**
 * Append the message that we received into the Shipping Instructions attribute. Use this method only for debugging purposes.
 */
void debug(def msg) {
    String si = header.getAttribute("ShippingInstructions");
    header.setAttribute("ShippingInstructions", si + ", " + msg.toString());
}