For customizing WebCenter Enterprise Capture, the JavaScript engine included with the Java Runtime Environment can be used. The developer's guide for WebCenter Enterprise Capture contains two sample client scripts that can be used to modify the standard behavior of the Capture client that runs in the browser. The two samples do the following tasks:
Sample 1: This sample script customizes client behavior in the following ways:
Sample 2: This sample script customizes client behavior in the following ways:
These scripts create a starting point for further client side customizations in Enterprise Capture. To extend the samples a bit further, the following script displays how to call a web service and populate a client profile field automatically. This example pulls a stock quote from a Yahoo Finance public REST API to demo how to call the REST service, parse the JSON response, and set the Capture field value.
Note that using the JavaScript engine, packages and classes that need to be included can be imported in either of the following ways:
importClass(java.awt.event.KeyEvent); importPackage(java.io, java.net);
For the example script that follows, the java.io and java.net packages are required, since calling the web service will use the classes URL and HttpUrlConnection. To read the JSON response, an InputStreamReader and BufferedReader classes are used.
importClass(java.awt.event.KeyEvent); importPackage(java.io, java.net); function DocumentSelected(event) { DocumentSelectedEvent println("DocumentSelected: " + event.getDocument().getTitle()); var MY_FIELD = "MetaField"; // The name of the metadata field to populate var document = event.getDocument(); var batch = document.getParentBatch(); var fieldDef = batch.getWorkspace().getFieldDefinitions().findByName(MY_FIELD); if (fieldDef != null) { var fieldId = fieldDef.getId(); var fields = document.getFields(); var field = fields.get(fieldId); //Setup URL to call Yahoo Finance service var yqlHostAndContext = "http://query.yahooapis.com/v1/public/yql"; var yqlQuery = "select * from yahoo.finance.quotes where symbol in ('ORCL')"; var yqlEnv = "http://datatables.org/alltables.env"; //Encode uri parameters var urlStr = yqlHostAndContext + "?q=" + encodeURIComponent(yqlQuery) + "&env=" + encodeURIComponent(yqlEnv); println(urlStr); var url = new URL(urlStr); var conn = url.openConnection(); //Returns HttpUrlConnection conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); var responseCode = conn.getResponseCode(); println("Sending 'GET' request to URL : " + url); println("Response Code : " + responseCode); if(responseCode == "200"){ var is = conn.getInputStream(); var isr = new InputStreamReader(is); var br = new BufferedReader(isr); var response = new java.lang.StringBuffer(); var line; while ((line = br.readLine()) != null) { response.append(line); } br.close(); conn.disconnect(); println(response); var jsonObj = JSON.parse(response); var price = jsonObj.query.results.quote.LastTradePriceOnly; //Set the field value field.setValue(price); } else{ //Could throw an error instead, but for sample script just setting meta field to a generic error string so user can see it. field.setValue("ERROR getting stock price. HTTP Response code:" + responseCode ); } // Save the document data document.persist(); } }
When the script succeeds, the last trading price value of the ORCL stock will be placed automatically into the field (MetaField).
When troubleshooting client side scripts, see the Java Console. This is where ECMA errors or other syntax errors will appear. Note that when updating client scripts, the Enterprise Capture managed server does not need to be restarted. Logout of the client profile and login once again, and the updated client script will load.
Oracle Support has additional as-is samples for customizing and enhancing the Enterprise Capture import processor, recognition processor, and client profiles. See these knowledge base articles for other example scripts.