Extend Shipping

Use these code examples to help you create order management extensions that manage shipping.

Some of these examples test a value for the purchase order number on the order header. This test isolates the extension and prevents it from affecting other developers who might also be running test code. For details, see Overview of Creating Order Management Extensions.

Validate Ship-to, Bill-to, and Sold-to Attributes

Get values for the Ship-to, Bill-to, and Sold-to attributes from the order header. Compare them to the customer account details and validate that they're all for the same customer.

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

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

if (poNumber == null) return;

if (!poNumber.startsWith("PMC TEST")) return;

List < Message > messages = new ArrayList < Message > ();

boolean relationExists = false;

def soldTo = header.getAttribute("BuyingPartyIdentifier");
def shipTo = header.getAttribute("ShipToPartyIdentifier");
def billTo = header.getAttribute("BillToCustomerIdentifier");

messages.add(new Message(Message.MessageType.ERROR, "Sold to is " + soldTo));
messages.add(new Message(Message.MessageType.ERROR, "Ship to is " + shipTo));
messages.add(new Message(Message.MessageType.ERROR, "Bill to is " + billTo));

if (header.getAttribute("BuyingPartyName") == header.getAttribute("BillToCustomerName"))
    relationExists = true;

messages.add(new Message(Message.MessageType.ERROR, "Buying Party Name is  " + (header.getAttribute("BuyingPartyName"))));
messages.add(new Message(Message.MessageType.ERROR, "Bill to Customer Name is  " + header.getAttribute("BillToCustomerName")));


def CustPVO = context.getViewObject("oracle.apps.cdm.foundation.parties.publicView.customerAccounts.CustomerAccountRelationshipPVO");
def vc = CustPVO.createViewCriteria();
def vcrow = vc.createViewCriteriaRow();
vcrow.setAttribute("RelatedCustAccountId", soldTo);
def rowSet = CustPVO.findByViewCriteria(vc, -1);

messages.add(new Message(Message.MessageType.ERROR, "Found a row: " + rowSet.hasNext()));

while (rowSet.hasNext()) {
    def row = rowSet.next();
    def billtorelation = row.getAttribute("CustAccountId");
    if (billtorelation == billTo) {
        relationExists = true;
    }
}

//header.setAttribute("ShippingInstructions", header.getAttribute("ShippingInstructions") + ", " + relationExists);

/*
if( !relationExists) {
 
  messages.add(new Message( "Bill To Customer is not related with Sold To"));
}  
*/
ValidationException ex = new ValidationException(messages);
throw ex;

Set the Default Value for Ship-To Address According to Business Unit

import oracle.apps.scm.doo.common.extensions.ValidationException;
import oracle.apps.scm.doo.common.extensions.Message;
 
List<Message> messages = new ArrayList<Message>();
 
def buNumber = header.getAttribute("BusinessUnitIdentifier");
 
def lines = header.getAttribute("Lines");                                                            
if(!lines.hasNext()){
 messages.add(new Message( Message.MessageType.ERROR,"No lines available"));
}
while( lines.hasNext() ) {                                                                           
  def line = lines.next();
//Add more business units according to your requirements. 
  if(buNumber==204){
    setShipToPartySiteId(line,messages,1220);//Have to pass the ShipToPartySiteId
    }
  if(buNumber==500){
    setShipToPartySiteId(line,messages,1222);
    }
}//end of while
 
if(!messages.isEmpty()) {                          
        ValidationException ex = new ValidationException(messages);
        throw ex;
   }
 
 
def setShipToPartySiteId(def line,List<Message> messages, def partySiteId){
  def partySiteUsgFlag = getPartySiteUssage(partySiteId);
  if(!partySiteUsgFlag){
      messages.add(new Message( Message.MessageType.ERROR,"The Ship-to Address isn't valid. Examine your setup."));
      return null;
  }//shipBeginDate  null check
  else{
    header.setAttribute("ShipToPartySiteIdentifier",partySiteId);
    line.setAttribute("ShipToPartySiteIdentifier",partySiteId);
  }
   return null;
}
 
def getPartySiteUssage(Long partySiteId) {
def PartySiteUsePVO = context.getViewObject("oracle.apps.cdm.foundation.parties.publicView.analytics.PartySiteUsePVO");       
  def vc = PartySiteUsePVO.createViewCriteria();                                                              
  def vcrow = vc.createViewCriteriaRow();
   
  vcrow.setAttribute("PartySiteId", partySiteId); 
  vcrow.setAttribute("SiteUseType", "SHIP_TO");
  def rowset = PartySiteUsePVO.findByViewCriteria(vc, -1);
    if(rowset.hasNext()){
    def row = rowset.next();
  return true;
  }
  else
    return null;
}

Cascade the Shipping Method from the Order Header to Order Lines

import oracle.apps.scm.doo.common.extensions.ValidationException;
import oracle.apps.scm.doo.common.extensions.Message;
def poNumber = header.getAttribute("CustomerPONumber");
List<Message> messages = new ArrayList<Message>();
 
if(poNumber != "shipmethod") return;
def ServiceCode=header.getAttribute("ShipClassOfServiceCode");
def Carrier=header.getAttribute("CarrierId");
def ShipModeOfTransport=header.getAttribute("ShipModeOfTransportCode");
 
def lines = header.getAttribute("Lines");
while (lines.hasNext()) {
            def line = lines.next();
            line.setAttribute("ShippingInstructions","ship_method_test");
            line.setAttribute("ShippingCarrierCode",Carrier);
            line.setAttribute("ShippingServiceLevelCode",ServiceCode);
            line.setAttribute("ShippingModeCode",ShipModeOfTransport);
}

Populate Shipping Instructions on Order Lines

Run this extension when the original order doesn't contain shipping instructions and you're revising the order.

import oracle.apps.scm.doo.common.extensions.ValidationException;
def poNumber = header.getAttribute("CustomerPONumber");
def orderNumber = header.getAttribute("SourceTransactionNumber");
 
if(orderNumber != "BMIQ-05022018-248408") return;
if(changeVN < 2) return;
 
def lines = header.getAttribute("Lines");
    while (lines.hasNext()) {
            def line = lines.next();
            def lineStatus = line.getAttribute("StatusCode");
            def shipInst = line.getAttribute("ShippingInstructions");
                if("CLOSED".equals(lineStatus) && shipInst != null){
                def refFlineId = line.getAttribute("ReferenceFulfillmentLineIdentifier");
                if(refFlineId == null){
                  continue;
                }
                def orginalFlinePRow = getFLineForRefFLine(refFlineId);
                if(orginalFlinePRow!=null) {
                   def lineStatus1 = orginalFlinePRow.getAttribute("FulfillLineStatusCode");
                   def shipInst1 = orginalFlinePRow.getAttribute("FulfillLineShippingInstructions");
                   if("CLOSED".equals(lineStatus1) && shipInst1 == null){
                      line.setAttribute("ShippingInstructions", null);
                   }
     }
    }      
}
 
def Object getFLineForRefFLine(Long refFlineId) {
def vo = context.getViewObject("oracle.apps.scm.doo.publicView.analytics.FulfillLinePVO");
   Object[] rows = vo.findByKey(refFlineId, 1);
   def originalFLine = rows[0];
   
   return originalFLine;
}

Make Sure Site Usage is Ship To

import oracle.apps.scm.doo.common.extensions.ValidationException;
def poNumber = header.getAttribute("CustomerPONumber");
 
if(poNumber != null && poNumber.equals("ship")) {
 
def lines = header.getAttribute("Lines");                                                            
while( lines.hasNext() ) {                                                                           
  def line = lines.next();                                                                           
  def partySiteId = line.getAttribute("ShipToPartySiteIdentifier"); 
 //throw new ValidationException("partySiteUseId :"+partySiteUseId);
  
  if(!(getPartySiteUssage(partySiteId)))                                                        
   throw new ValidationException("siteUssage is not shipto");
  }
 
}
 
Boolean getPartySiteUssage(Long partySiteId) {
def PartySiteUsePVO = context.getViewObject("oracle.apps.cdm.foundation.parties.publicView.analytics.PartySiteUsePVO");       
  def vc = PartySiteUsePVO.createViewCriteria();                                                              
  def vcrow = vc.createViewCriteriaRow();
   
  vcrow.setAttribute("PartySiteId", partySiteId); 
  vcrow.setAttribute("SiteUseType", "SHIP_TO");
  def rowset = PartySiteUsePVO.findByViewCriteria(vc, -1);
   
  if(rowset.hasNext())
  return true;
  else
    return false;
 
}