Validate Relationships Between Attributes

Create an order management extension that makes sure the sales order includes a relationship between the sold-to customer and the ship-to customer, and between the sold-to customer and bill-to customer.

If one of these relationships doesn't exist when you attempt to submit the sales order, then the extension stops the sales order from proceeding and displays an error message.

This topic uses example values. You might need different values, depending on your business requirements.

  1. In the Setup and Maintenance work area, go to the task.

    • Offering: Order Management

    • Functional Area: Orders

    • Task: Manage Order Management Extensions

  2. On the Manage Order Management Extensions page, on the On Start of Submission Request tab, create a new extension.

    Attribute

    Value

    Name

    Validate Relationships Between Attributes

    Description

    Make sure a relationship exists between the sold-to customer and the ship-to customer, and between the sold-to customer and the bill-to customer. If one of these relationships doesn't exist, then create an error and stop the sales order from proceeding.

  3. In the Definition area, add code.

    //import classes for validation exceptions and messages from Oracle Trading Community Architecture.
    import oracle.apps.scm.doo.common.extensions.ValidationException;
    import oracle.apps.scom.doo.comm.extensions.Message;
    
    // Make sure the extension runs only for your test sales order. If more than one developer uses your test environment, then this condition makes sure the code updates only your sales order. You must remove this condition in a production environment.
    def poNumber = header.getAttribute("CustomerPONumber" );
    if(poNumber == null) return;
    if( !poNumber.startsWith("MatchRelationship") ) return;
    boolean relationExists=false;
    
    //define the variables you will use to store the identifiers.
    def soldTo = header.getAttribute("BuyingPartyIdentifier")
    def billTo = header.getAttribute("BillToCustomerIdentifier")
    
    //if the relationship exists, then further validation is not necessary, so save the sales order, and then exit.
    if (header.getAttribute("BuyingPartyName")==header.getAttribute("BillToCustomerName"))
      relationExists=true;
    
    //determine what relationship currently exists between the bill-to customer and the sold-to customer.
    //reference the view object that stores the relationship. In this example, the CustomerAccountRelationship view object stores this relationship.
    def CustPVO = context.getViewObject("oracle.apps.cdm.foundation.parties.publicView.customerAccounts.CustomerAccountRelationshipPVO");
    
    //create the view criteria. 
    def vc = CustPVO.createViewCriteria();
    def vcrow = vc.createViewCriteriaRow();
    //RelatedCustAccountId is an attribute that stores the sold-to relationship, so you set vcrow to reference RelatedCustAccountId. You will examine it to determine whether the sold-to customer is related to the bill-to customer.
    vcrow.setAttribute("RelatedCustAccountId", soldTo);
    //Query the view object according to the criteria that you set in the previous line of code.
    def rowSet = CustPVO.findByViewCriteria(vc, -1);
    
    //Read through the row set. If a row exists that contains a relationship, then you have determined that a relationship exists between sold-to and bill-to, so save the sales order, and then exit.
    while (rowSet.hasNext()) {
      def row = rowSet.next();
      def billtorelation=row.getAttribute("CustAccountId")
      if (billtorelation == billTo)
      {
        relationExists=true;
      }
    }
    //Create an exception when a relationship does not exist and display an error message.
    //header.setAttribute("ShippingInstructions", header.getAttribute("ShippingInstructions") + ", " relationExists)
    
    if( !relationExists) {
    throw new ValidationException("The order submit failed because the bill-to customer is not related to the sold-to customer.");
    }
    

    This example is only for demonstration purposes in a development environment. It hard codes the message to display in the Order Management work area in the English language as The order submit failed because the bill-to customer is not related to the sold-to customer. To avoid problems with translation to other languages, don't code the message in a production environment.

    Instead, here's some code you can use to reference a message from the messaging framework.

    throw new ValidationException("lookup_code", "message name", token_values);

    where

    • lookup_code determines where and how to display the message in the Order Management work area. For example, you can reference more than one lookup code to display messages in different pie slices on the infolets in the Order Management work area, according to lookup code.

    • message name identifies the name of the message that exists in the messaging framework.

    • token_values specifies a list of the values to use in the tokens that the message contains. If the message doesn't contain any tokens, then use null.

    For example, here's some code that displays the contents of the FOM_CMN_INV_BILL_TO message.

    throw new ValidationException("ORA_MANAGE_EXTENSIONS", "FOM_CMN_INV_BILL_TO", null);

    Learn how to use a lookup_code with the ValidationException method. For details, see Methods That You Can Use with Order Management Extensions.

Test Your Set Up

  1. Navigate to the Order Management work area, create a new sales order, then click Submit.

    Attribute

    Value

    Customer

    Computer Service and Rentals

    Bill-to Customer

    Business World Inc.

    Purchase Order

    ValidateRelationshipsBetweenAttributes _run_extension

  2. Verify that the error dialog displays the message you coded.

    Computer Service and Rentals is the sold-to customer, Business World Inc is the bill-to customer, they don't match, so Order Management displays an error.

  3. Set the value, then click Submit.

    Attribute

    Value

    Bill-to Customer

    Computer Service and Rentals

  4. Verify that Order Management submits the sales order and sets the status to Processing.

    Computer Service and Rentals is the sold-to customer and the bill-to customer, they match, so Order Management processes the sales order.