The Digital Experience Platform blog covers the latest in innovative technologies to help you transform your business.

Move an email message to a custom folder on error conditions in an import script

Sripathy Rao
Product Manager

This is the scenario—you've an email with attachments you'd want to convert with an external tool.  If the conversion succeeds, you move to the next step.  Otherwise, you'd like to move this email to an 'Error' folder in the mailbox. 

As an Oracle WebCenter Enterprise Capture developer, you would be familiar with the concept of cancelling a file import via scripting. But if you were to cancel the preImportFile event, you know it will simply skip importing that particular attachment.  What if you wanted to skip processing the entire email and move it out of your Inbox?  If you were to throw an exception in the script during an Import Processor job configured to use Email source, it will cause the attachment processing to abort.  However, Capture will continue to retry processing this email and fail conversion as before.  How do you additionally tell Capture not to keep trying to process this email?

To overcome this, WebCenter Enterprise Capture 12c introduces an additional property importCancelAction you can add to your scripts. That way, scripts can cause the event to abort, and execute the failure condition by setting the cancel flag.  Here's how—

The script uses an external conversion program—Ghostscript.

// Check the GhostScript process exit code.
var exitCode = p.exitValue();
logger.info("GhostScript exit code:" + exitCode);

if (exitCode != 0) 
  // 'throw' is no longer required.
  // throw "Failed to convert " + originalPdf + 
  //      " using GhostScript. Exit code: " + exitCode;

  logger.severe("Failed to convert " + originalPdf + 
                " using GhostScript. Exit code: " + 
  logger.info(jobName + 
              ": Cancelling GhostScript import in exit code section");

The major change above is to set the import cancel action to “1” which means “abort / delete the batch”, and prevent the exception from getting thrown all the way up the Capture stack, so that the subsequent event cancelling statement continues to execute.

Don't miss the blog on What New in WebCenter Capture 12c.



Manjari Misra
Principal Member Technical Staff, Oracle WebCenter Capture Engineering

Manjari graduated from a premier institute and joined Oracle with a passion to learn new technologies, and make it work for the customers.  She is responsible for WebCenter Enterprise Capture product development.  A seasoned multi-role Java engineer that she is, has worked on several areas of Capture development—planning, design, prototyping, implementation, security, both on the core server and client.  In her earlier responsibilities, she  implemented a plug-in for Windows Explorer to view sealed documents with VC++, Win32 shell programming.

Outside of work, Manjari is a yoga enthusiast, a self-professed movie buff, and practices Kathak, an Indian classical dance form.

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.