Test Your Order Management Extension

Test your order management extension.

Validate Your Code

Enter your code into the Definition area of the Edit Extensions page, then click Validate to validate your design-time code. Order Management will make sure you correctly formatted your code, such as correct usage of parentheses, semicolons, and so on.

If an error happens at runtime, then Order Management handles the error in the same way it handles any other error. It displays the cause of failure, extension name, and event name. It displays these details in the Order Management work area and in the log files. It can handle these runtime errors.

  • Reference to an attribute or method that isn't valid

  • Incorrect reference between the message name and a token

  • Incorrect reference to a web service name

Use Logging to Test Your Code

Include debugging tests during development to test your code and verify that it runs as expected.

Using Logging to Test Your Code

Note

  • After you finish testing and are ready to deploy your extension to production, modify your debugging logic to write to a log file instead of commenting your test code. Writing to the log file can be helpful for future possible troubleshooting. If you write data to the log file in a production environment, then you must contact Oracle Support or a customer administrator to get view access to the log files that include application diagnostic data.

  • Use the log files to evaluate performance. For example, if you write a lot of extension code, then examine and monitor performance to make sure your code doesn't impact performance in a negative way.

    For example, extension code typically performs a significant amount of validation immediately after the Order Entry Specialist clicks Submit. If Order Management requires a long amount of time to finish the submit, such as five minutes, then it might be necessary to look closely at your code to determine whether it contains some logic you can streamline.

Use the Debug Method

Use the Debug method at various points in your code during development to write variables and other values to an attribute that you can examine in work area Order Management. This example calls debug three times, then writes the contents of debug into the ShippingInstructions attribute.

Using the Debug method at various points in your code

You can then write your code so it displays these contents in the Shipping Instructions attribute in the Order Management work area, then examine this display output to determine the values of various attributes and variables that exist at various points in your code.

When you're ready to deploy to production, modify void debug. For example, assume you use this code to write your debug contents.

void debug(def msg)
 {String si = header.getAttribute("ShippingInstructions");
 header.setAttribute("ShippingInstructions", si + ", " + msg.toString());

Modify this code so it writes to the log. You replace header.setAttribute with logger.logFine. For example:

void debug(def msg)
 {String si = header.getAttribute("ShippingInstructions");
 logger.logFine("ShippingInstructions", si + ", " + msg.toString());

Use this approach so you can change only a single line in your code, which is useful if you have 10s of lines that call debug. You can also comment each line that calls the debug method, but commenting runs the risk of missing lines that call debug, or accidentally commenting a line that doesn't call debug but that's critical to your code logic.

Here's the complete code for this example.

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

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

if( poNumber != "CreditCheck" ) 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>";

// invoke the Check Check service using web service connector name 'CreditCheckService'. The connector is set up using task 'Manage External Interface Web Service Details'. Since this is an external service that is secured
// using message protection policy, we have registered the the https URL of the service
def response = context.invokeSoapService("CreditCheckService", payLoad); 

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

// The response XML sent by the Credit Check service contains an element named 'Response'. A YES value indicates that credit check passed. Let us extract the contents of Response tag. The following XML API will return all nodes (tags)
// with name 'Response' in a NodeList element. We are expecting only one such 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 with name 'Response' (we are expecting only one), and gets its text content
String ccResponse = nodeList.item(0).getTextContent();

debug(ccResponse);

// Check if credit check passed
if( ccResponse != 'YES' ) {
 // Credit check failed. Use a warning validation exception here.
 throw new ValidationException( new Message(Message.MessageType.WARNING, "Credit check failed.") );
}
else {
 // Credit check passed
 // Write the credit check response in an EFF attribute.
 def psiContext = header.getOrCreateContextRow("ComplianceDetails");
 psiContext.setAttribute("_ComplianceInfo", ccResponse);   
}

/**
* Appends passed in msg to the Shipping Instructions attribute. This method has been implemented only for debugging purposes.
*/
void debug(def msg) {
 String si = header.getAttribute("ShippingInstructions");
 header.setAttribute("ShippingInstructions", si + ", " + msg.toString());
}