Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite 6
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions
  • Government

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / LiveCycle Developer Center /

Using the Execute Script Service in LiveCycle Workbench ES2 to build XML data

by Deke Smith

Deke Smith
  • twintechs.com

Content

  • Using the Execute Script Service in a Process
  • Creating XML Using the Execute Script Service
  • Where to go from here

Created

4 April 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
LiveCycle Designer ES4XML
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

User level

Intermediate

Required products

  • LiveCycle Designer ES4 (Download trial)
  • LiveCycle Workbench ES (Download trial)

There is a lot of XML involved with Adobe LiveCycle Process Management workflows, for instance: XML information may be built in a process and sent to a Flex application in Adobe LiveCycle Workspace ES2, used for systems settings, or passing information to and from forms. There are many instances where a LiveCycle developer needs to manage XML, and many times this requires that the XML be managed via a LiveCycle process.

When dealing with simple XML settings, one may use the "Set Value" service, which is a default LiveCycle service. This service sets the value of one or more data items in the process data model. For very simple conditional logic "if this, then that" scenarios, this service can suit the purpose.

However, in more complex situations, the Set Value service isn't as effective. In these situations, one needs to rely on a more robust set of programming commands, such as those provided by a programming language like Java. Using Java to build complex XML can be much easier and more clear than building an XML document from simple text within the Set Value service. In addition, it is easier to include conditional programming in Java than within a Set Value service.

Using the Execute Script Service in a Process

Within the set of the standard LiveCycle services available in LiveCycle Workbench ES2, is the "Execute Script" service. This service lets you execute scripts in processes and provides the "executeScript" operation to do so.

Create an Application and a Process with the "Execute Script" Service Defined as an Activity

Overall application and process creation is out-of-scope for this tutorial, but for the sake of this instruction, we have created an application named "DemoApplication02". Assuming that an application has already been created, we need to create a process in this application to call the executeScript service. To add a process to the application that includes the "Execute Script" service:

  1. Right click on your application and select "New". In "New" slide-out menu, select "Process". Name your process accordingly, add a description if necessary, and select the icon you wish to represent this process. For the purposes of this tutorial, we have created a process and named it the "executeScriptDemoProcess".
  2. Define your start points, or simple opt to add your start points later.
  3. The process is now created and should automatically open in the "Process Design" window. In this window, click on the Activity Picker icon at the top of the Process Design window and drag the new activity onto the swim lane. At this point, the "Define Activity Window" should appear (see Figure 1 below).
the Define Activity Window should appear.
Figure 1. the Define Activity Window should appear.
  1. The executeScript service can be found under the "Foundation" set of services. The Services name lists the object as "Execute Script – 1.0" with the Operation name "executeScript". Click to select this item.
  2. This process should now be created, and by default the "Process Properties" window should appear in the pane on the left.

Add a Script to the Process with the "Execute Script" Service

Once the process has been created with the "Execute Script" Service activity defined, one can then add a script to this process. To add a script to this process:

  1. Navigate to the "Process Properties" palette. Within this palette, expand the "Input" section and click on the "…" icon.
  2. In the text box that appears write your script. When the script has been written press OK (see Figure 2).
When the script has been written press OK.
Figure 2. When the script has been written press OK.

Creating XML Using the Execute Script Service

Once a process has been created with the Execute Script service included, one can then use this script to create XML. One would write the scripts described below in the text box described in the Add a Script to the Process with the "Execute Script" Service section above.

About the Execute Script Service's Technology

In order to know what the abilities and limitations of the Execute Script service are, one must know the technological underpinnings of the service. LiveCycle uses the Apache Xerces Document Object Model (DOM) parser to create and store XML variables within processes. Xerces is a Java implementation of W3C's Document Object Model specification; defined here. The DOM specification is a standard way of manipulating XML that has been around since 1998. The Java implementation of Xerces, Xerces-J, supports DOM Level 2 version 1.0.

The Java classes used to store XML variables are:

  • org.apache.xerces.dom.NodeImpl and
  • org.apache.xerces.dom.DocumentImpl.

DocumentImpl is a subclass of NodeImpl, so it can be supposed that any XML process variable is a NodeImpl derivation. You can find the documentation for NodeImpl here.

A Sample XML Creation Using the Execute Script Service

Here is the example of creating XML, within an Execute Script service. The process has a variable, node, that is of type XML. The end result of this activity will be an XML document. What that document does, or how it applies to the overall process is out-of-scope for this tutorial; ultimately it comes down to what the XML is required to do in the overall application. As was mentioned in the introduction, XML can be used for many purposes in LiveCycle forms and processes, this is simply an explanation of how to code the Execute Script activity to output a simple XML document.

A simple Java script to output XML would looks something like this:

import org.apache.xerces.dom.DocumentImpl; import org.w3c.dom.Document; import org.w3c.dom.Element; Document document = new DocumentImpl(); Element topLevelResources = document.createElement("resources"); Element resource = document.createElement("resource"); resource.setAttribute("id", "first item id"); resource.setAttribute("value", "first item value"); topLevelResources.appendChild(resource); document.appendChild(topLevelResources); patExecContext.setProcessDataValue("/process_data/node", document);

Note: that the aforementioned DOM objects must be imported into the script.

The result of this simple script is a new XML document with a variable node that is set to:

<resources> <resource id="first item id" value="first item value"/> </resources>

Using an Iterative loop to Add Nodes to the XML

Nodes can be added to an existing XML variable within the process, too. The variable, node, contains the XML object we just created.

Document document = patExecContext.getProcessDataValue("/process_data/node"); NodeList childNodes = document.getChildNodes(); int numChildren = childNodes.getLength(); for (int i = 0; i < numChildren; i++) { Node currentChild = childNodes.item(i); if (currentChild.getNodeType() == Node.ELEMENT_NODE) { // found the top level node Element newResource = document.createElement("resource"); newResource.setAttribute("id", "second item id"); newResource.setAttribute("value", "second item value"); currentChild.appendChild(newResource); break; } } patExecContext.setProcessDataValue("/process_data/node", document);

The variable node in the XML is now set to:

<resources> <resource id="first item id" value="first item value"/> <resource id="second item id" value="second item value"/> </resources>

Where to go from here

To learn more about the Set Value service mentioned in the introduction section of this document, refer to the following:

  • Adobe's official LiveCycle Help documentation that refers to services
  • the main Adobe Help entry for the Execute Script service

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Transforming JDBC service output using the Query for Multiple Rows as XML operation
  • Record-based processing using LiveCycle Output ES
  • Displaying a list of participants for a review stage in e-mail for Managed Review & Approval Solution Accelerator 9.5
  • Pre-populating dropdown lists in dynamic PDF forms from a back-end data source using LiveCycle ES2.5
  • Binding an XML Schema Document (XSD) to repeating subform elements using Adobe LiveCycle Designer

Products

  • Adobe Creative Cloud
  • Creative Suite 6
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy (Updated) | Cookies

Ad Choices