X

Best Practices from Oracle Development's A‑Team

Publishing update events from SCM cloud R11 using BI publisher reports and scheduled job on Oracle cloud.

Introduction

In Supply Chain Management (SCM) cloud’s work execution module, when a manufacturing work order’s steps are completed or its status changes, customers might want to capture and propagate the changes to other target systems. These target systems might take actions such as starting equipment or perform analytics, using the propagated data. SCM cloud, as of R11, does not publish events for work order status changes or work order step completions. This article elaborates on an approach to generate events using a combination of BI publisher reports in SCM cloud and a scheduled job deployed in Oracle cloud.

Main Article

SCM cloud keeps audits of actions performed on work orders. Reports in XML format can be generated from contents of audit table using SCM's out-of-box BI publisher. BI publisher reports can be invoked through a web service. Coupled with a Quartz scheduler job, these reports can be used to emulate published events. The scheduler job can take actions such as posting the SCM changes to a queue, to update a database table or to invoke a web service of a 3rd party application. Note that this might be a suitable option for solutions that do not need events in real time, provided the inherent delays in updating the audit tables and interval between subsequent runs of the job. Intermediate level knowledge of BI publisher, WebLogic and Java is required to follow the instructions provided in subsequent sections.

Figure 1 – Overview of the solution

BI Publisher reports in XML format

BI publisher reports are based on data models. So, first create a data model and ensure that the resulting data meets the requirements. Here are the overall steps for creating a data model from SCM tables.

  • Navigate to “Reports and Analytics” from main menu.
  • On initial BIP page, click on “Browse Catalog” on the top.
  • On catalog page, click on “New” and then “Data Model”.
  • Create a SQL query with SCM data source, view the results and save.

Below is a sample query to obtain work order status changes. The term “:LastObservedDate” in WHERE clause is a parameter that needs to be passed, either at BI Publisher prompt or over web service call's XML payload. This query returns results sorted by date and time of change in descending order. The next time this query is run, the latest change date and time should be passed as “:LastObservedDate”, so that events captured in previous run are excluded.

SELECT "WO"."WORK_ORDER_NUMBER" as "WORK_ORDER_NUMBER",  "WOSTATHIST".STATUS_CHANGE_DATE as "STATUS_CHANGE_DATE",  "WOSTATUS".WO_STATUS_CODE as NEW_WO_STATUS_CODE FROM "FUSION"."WIE_WORK_ORDERS_B" "WO",  "FUSION"."WIE_WO_STATUS_HISTORY" "WOSTATHIST", "FUSION"."INV_ORGANIZATION_DEFINITIONS_V"  "ORG",  "FUSION".WIE_WO_STATUSES_B  "WOSTATUS" WHERE  WOSTATHIST.WORK_ORDER_ID = WO.WORK_ORDER_ID AND          ORG.ORGANIZATION_ID = WO.ORGANIZATION_ID AND  WOSTATHIST.STATUS_CHANGE_DATE > :LastObservedDate AND  WOSTATHIST.NEW_STATUS_ID=WOSTATUS.WO_STATUS_ID ORDER BY WOSTATHIST.STATUS_CHANGE_DATE DESC

 

View the data output and save it as sample data, by clicking “Save as sample data”. Save the data model.

To create a XML report, navigate to Catalog, click “New”, then select “Report”.

  • Choose Data model, by clicking on “Use Data Model” and select the data model created in previous steps.

02

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Choose table format, then drag and drop fields into the report layout. Save the report.

03

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

04

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Once the report is saved, modify the report to product only XML output.
  • Click on catalog on the menu and locate the report we just saved.
  • Click “Edit” for the report. On the next page, click on “View a list”.

05

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • In the list of layouts, click on “Output formats” for the layout.

06

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • In the list of format, uncheck all options but “Data (XML)”. Save the report.

07

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now, the report is ready to produce the status changes of work orders in XML format.

Here is another query that lists the completion of steps in a work order. This query, similar to the previous one, accepts a parameter to list only the completions that occurred since the last run.

SELECT    "WOOPTX"."ORGANIZATION_ID" as "ORGANIZATION_ID",  "WOOPTX"."WORK_ORDER_ID" as "WORK_ORDER_ID",  "WOOPTX"."WO_OPERATION_ID" as "WO_OPERATION_ID",  "WOOPTX"."TRANSACTION_TYPE_CODE" as "TRANSACTION_TYPE_CODE",  "WOOPTX"."TRANSACTION_DATE" as "TRANSACTION_DATE",  "WOOP"."OPERATION_SEQ_NUMBER" as "OPERATION_SEQ_NUMBER",  "WO"."WORK_ORDER_NUMBER" as "WORK_ORDER_NUMBER",  "WO"."WORK_ORDER_ID" as "WORK_ORDER_ID_1",  FROM      "FUSION"."WIE_WORK_ORDERS_B" "WO",  "FUSION"."WIE_WO_OPERATIONS_B" "WOOP",  "FUSION"."WIE_OPERATION_TRANSACTIONS" "WOOPTX",  "FUSION"."INV_ORGANIZATION_DEFINITIONS_V" "ORG"  WHERE     WOOPTX.WORK_ORDER_ID = WO.WORK_ORDER_ID AND  WOOPTX.WO_OPERATION_ID = WOOP.WO_OPERATION_ID AND  WOOPTX.TRANSACTION_TYPE_CODE='OP_COMPLETION' AND  ORG.ORGANIZATION_ID = WO.ORGANIZATION_ID AND  WOOPTX.TRANSACTION_DATE > :LASTOBSERVEDDATE  ORDER BY WOOPTX.TRANSACTION_DATE DESC

 

Running BI Publisher reports through web service

The next step is to ensure that the report output could be obtained through BI publisher web service.

The web service URL is typically https://<BI_hostname>:<port>/xmlpserver/services/v2/ReportService.  Substitute <BI_hostname> and <port> with values suitable for a specific environment.

A sample XML payload to run report is provided below, with parameter and security tokens. Note the date and time value passed for parameter LastObservedDate.  The response contains Base64 encoded XML data from BI publisher report.

 

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">    <S:Body>      <runReport xmlns="http://xmlns.oracle.com/oxp/service/v2">          <reportRequest>            <XDOPropertyList xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <attributeCalendar xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <attributeFormat>xml</attributeFormat>            <attributeLocale xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <attributeTemplate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <attributeTimezone xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <attributeUILocale xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <byPassCache>false</byPassCache>            <dynamicDataSource xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <flattenXML>false</flattenXML>            <parameterNameValues>                <listOfParamNameValues>                  <item>                     <UIType xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                     <dataType xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                      <dateFormatString xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                      <dateFrom xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                      <dateTo xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                      <defaultValue xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                     <fieldSize xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                      <label xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                      <lovLabels xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                      <multiValuesAllowed>false</multiValuesAllowed>                      <name>LastObservedDate</name>                      <refreshParamOnChange>false</refreshParamOnChange>                      <selectAll>false</selectAll>                      <templateParam>false</templateParam>                      <useNullForAll>false</useNullForAll>                      <values>                        <item>2016-08-30T18:56:49.232+00:00</item>                     </values>                  </item>                </listOfParamNameValues>            </parameterNameValues>            <reportAbsolutePath>/~SCM_IMPL/OOW-demo-reports/WorkOrderStatusHistory.xdo</reportAbsolutePath>            <reportData xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <reportOutputPath xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <reportRawData xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>            <sizeOfDataChunkDownload>-1</sizeOfDataChunkDownload>          </reportRequest>          <userID>scm_username</userID>          <password>scm_password</password>      </runReport>    </S:Body> </S:Envelope>

 

Quartz Scheduler and job

The final task is to develop a job that could be triggered by a quartz scheduler periodically. This job invokes the BI publisher web service shown in previous section, gets the XML data from report, updates the target systems and stores the last observed date and time of status change for look-up by the next run of the job.. The java snippets provided were part of code deployed to a WebLogic container hosted on an Oracle cloud compute node. It could also be deployed to an Oracle Java Cloud Service (JCS) instance.

Quartz scheduler is an open source library available for several platforms, among them, Java. Quartz libraries for Java are available here.

The scheduler and job could perform these tasks:

  1. A web service façade to start and stop the scheduler. This is essential for controlling the job remotely
  2. A job (Java class) that is triggered by the scheduler.
  3. A module for each of these functions in the job
  4. Invoke the BI publisher web service
  5. Perform the relevant publishing and updating functions for target systems
  6. Store the last observed status change date-time to be used for next run


For the sake of brevity, code snippets for essential aspects of the solution are provided.

Quartz scheduler’s usage is well-documented in Quartz blogs and forums. This snippet shows how to schedule a job that runs every 10 seconds:

statustrigger = TriggerBuilder.newTrigger()  .withSchedule(SimpleScheduleBuilder.simpleSchedule()  .withIntervalInSeconds(Integer.parseInt(10))  .repeatForever())  .build(); statussch = schFactory.getScheduler(); statussch.start(); statussch.scheduleJob(statusjob, statustrigger);

Code for invoking BI Publisher web service:

try {  ReportRequest reportRequest = new ReportRequest();  reportRequest.setAttributeFormat("xml");  reportRequest.setReportAbsolutePath("/~SCM_IMPL/demo-reports/WorkOrderStatusHistory.xdo");  ArrayOfParamNameValue pNameValue = new ArrayOfParamNameValue();  ParamNameValue nameValue = new ParamNameValue();  ParamNameValues paramNameValues = new ParamNameValues();  nameValue.setName("LastObservedDate");  ArrayOfString aos = new ArrayOfString();  //set the static var so that the file is not read next time.  strLastObservedDate = strDateTime;  //Set the value as parameter for the report  aos.getItem().add(strDateTime);  nameValue.setValues(aos);  pNameValue.getItem().add(nameValue);  paramNameValues.setListOfParamNameValues(pNameValue);  reportRequest.setParameterNameValues(paramNameValues);  reportRequest.setSizeOfDataChunkDownload(-1);  ReportResponse response = runReport(reportRequest, "scm username", "scm password");  String strReport = new String(response.getReportBytes());  System.out.println("WOSTATUS-getreport-Report length is " + strReport.length()); } catch (Exception e) {  e.printStackTrace(); }

Summary

This article explains how to publish events out of Supply chain Management cloud using out-of-box reporting tools in SCM cloud and a scheduled job deployed to either JCS or Oracle Compute node. This approach is suitable for R11 of SCM cloud. Subsequent releases of SCM cloud might offer equivalent or better event-publishing capabilities out-of-box. Refer to product documentation for later versions, before implementing a solution based on this article.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha

Recent Content