Previous Topic: Content Object Reference


GEL Tag Library Reference

This section contains the following topics:

Tag Libraries

GEL Tag Library

Core Tag Library

SOAP Tag Library

Tag Libraries

Every GEL tag is associated with one of the following tag libraries:

GEL Tag Library

To use the GEL tag library, include the following namespace declaration in your script.

<gel:script
xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

gel:script - Defining GEL Scripts

This is the root element for all GEL scripts.

This element is the core:jelly:

escapeText

Values:

Default: true

Type: Boolean

trim

Values:

Default: true

Type: Boolean

gel:parse - Parsing XML

Use gel:parse to generate an XML document in memory from a file, InputStream (obtained with ftp:get tag), or GEL script content.

Using other get tags, you can:

This tag has the following attributes:

file

Optional. The file to read. Specify the input path and file name or the InputStream from the ftp:get tag.

If this attribute is not set, the content of this tag is used.

Type: File or InputStream

var

Required. The name of the variable that contains the XML document to be generated.

Type: String

Example 1

<gel:script 
  xmlns:gel=”jelly:com.niku.union.gel.GELTagLibrary“>
  <gel:parse var=”xmldoc” file=”e:\temp\BB1.xml”/>

Example 2

<gel:script xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">
  <gel:parse var="xmldoc"> 
    <groups>
      <group code="CTU">CTU Team</group>
      <group code="DS23">SWAT Team</group>
    </groups>
  </gel:parse>
</gel:script>

More information:

soap:message - Specifying SOAP XML Messages

gel:set - Setting XML Document Values

Once you use gel:parse or soap:invoke and have an XML node or document, you can use gel:set to retrieve certain element content or attributes and set the value to a variable. You can also use gel:set to change content (including text and attributes) or add an element with its full structure as a child into another element.

Example

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <!-- point A -->
  <gel:parse var="groups">
    <groups>
      <group code="DS23">SWAT Team</group>
    </groups>
  </gel:parse>

  <!-- point B -->
  <gel:set select="$groups/groups/group" var="groupNode"/>
  <!-- point C -->
  <gel:set select="$groupNode/@code" var="code" asString="true"/>
  <!-- point D -->
  <gel:set value="${groupNode}" select="$groups/groups" insert="true"/>
  <!-- point E -->
  <gel:set value="CTU Team" select="$groupNode/text()"/>
  <!-- point F -->
  <gel:set value="CTU" select="$groupNode/@code"/>
  <!-- point G -->
  <gel:set select="$groups/groups" var="x" asString="true"/>
  <gel:out>${x}</gel:out>

</gel:script>

The GEL context contains these values:

When you print the document referred by groups, you will see:

<?xml version="1.0" encoding="UTF-8"?>
<groups>
	<group code="CTU">CTU Team</group>
	<group code="DS23">SWAT Team</group>
</groups>

Retrieve XML Document Values

Use the attributes var and select to retrieve values from an XML document.

If the select refers to a non-existing path, no value setting is performed (that is, if var refers to a variable that is not set in another place, it will be null).

To retrieve the text content of a node

<set var="…" select="$doc/…/node_name/text()" 
	asString="true"/>.

To retrieve a certain attribute

<set var="…" select="$doc/…/node_name/@attribute_name" 
	asString="true"/>

To retrieve a node, including its sub-nodes

<set var="…" select="$doc/…/node_name"/>.

Modify XML Document Values

Use the attributes var and select together to set values in an XML document. The select attribute must refer an existing path. If select = "$doc/group" and there is not an element called group in the document or node referred by doc, an exception will be thrown. If select="$doc/group/text()" and the <_group> element does not contain text content, an exception will be thrown.

If the node does not have text content, to set the text content of a node

<set value="…" select="$doc/…/node_name"/>
-or-
<set value="…" select="$doc/…/node_name/text()"/>

If you reverse the previous two examples, you will get an exception (because a node does not have any child text but you referred to it with text()), or the item you tried to set will be appended to the previous text content.

If you are not sure if the node for which you want to set text content has text content already, it is best to retrieve its text value first and then use core:if to check if it exists before proceeding.

To set the attribute value of node

<set value="…" select="$doc/…/node_name/@attribute_name"/>.

To set a node into another document

<set value="${node_var}" select="$doc/…/node_name"/>

You can use attribute insert if you are adding a node to a path or to have this node replace whatever is referred to by the path.

The following describes the gel:set:

var

Either var or value is required. The variable to export for the item being iterated over. The variable can be a string, a number, etc.

Type: String

value

Either var or value is required. If the value is a node, it is inserted into the position specified by select; otherwise the string value is set as the text content or attribute specified by select.

Type: Object

select

Required. The XPath expression to use to retrieve a value.

Type: org.jaxen.XPath

asString

Optional. If set to "true", the value specified by select is converted to a string and saved into the variable referred to by var. If set to "false", the node specified by select is set to the variable referred by var.

Default: false.

this is ignored when var is not set.

Type: Boolean

insert

Optional. If set to "true", the node referred to by value is inserted as a child node to the node specified by select. If set to "false", the node referred to by value is used to replace the node specified by select.

Default: false. This is ignored when value is not set, or set but not with a node value.

Type: Boolean

gel:expr - Evaluating Expressions

Use this tag to evaluate an expression as text. Most often the expression resolves to an XML element as illustrated in the following examples.

Example 1

<gel:script
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:parse var="group">
    <group code="CTU">CTU Team</group>
  </gel:parse>

  <core:comment>
    The code is <gel:expr select="$group//@code"/>
  </core:comment>

</gel:script>

Example 2

The previous example is equivalent to the following gel:set example:

<gel:script
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:parse var="group">
	<group code="CTU">CTU Team</group>
  </gel:parse>

  <gel:set var="code" select="$group//@code" asString="true"/>
  
  <core:comment>
    The code is ${code}
  </core:comment>

</gel:script>

The following describes gel:expr

select

Required. The XPath expression to retrieve the value.

Type: XPath

gel:parameter - Defining Parameters

Use this tag to define parameters that can be used in a GEL script.

Example

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:parameter var="hostname" default="http://localhost/niku/xog"/>
  <gel:parameter var="username" default="admin"/>
  <gel:parameter var="password" default="niku2000" secure="true"/>

  <gel:out>Host = ${hostname}</gel:out>
  <gel:out>User = ${username}</gel:out>

</gel:script>

Use gel:parameter Instead of core:set

When a GEL script is executed from the console, there is no difference between using gel:parameter and core:set.

When gel:parameter is executed as a process, all parameters that were defined using the <gel:parameter> tag appear with input boxes on the action definition page. You can enter a value for a parameter to override the default value in the script.

You should use gel:parameter for values that may be changed by process administrators (such as URL, hostname, username, etc.). Also use this for values which should be kept discrete, like passwords.

You can only define one parameter name at a time. For example, if you use logic such as "if a certain condition, log in as userA, otherwise userB," instead of defining "username" in two places, use this parameter to log in, define two properties "usernameA" and "usernameB", and then use the <core:set> tag to pick one of those two properties to set into a variable in the "if" block.

A parameter can be used later just like other variables (that is, ${var}).

The following describes gel:parameter:

var

Required. The parameter name.

Type: String

default

Optional. The parameter default value. Provide this value if you want the script to be executable from the console (even if this parameter is not secure).

Type: Object

secure

Required. Set this attribute to "true" if the parameter content should not be shown in plain text to process administrators.

Default: false

Type: Boolean

gel:getDocument - Requesting XML Documents

A process can be invoked in the following ways:

When a process is invoked as a web service, the request is an XML document. You can use this tag to get that document, find what needs to be done, and then perform actions accordingly.

If an XML document is set using the gel:setDocument tag in one step of a process, you can use this tag to retrieve the document a later step of the same process.

var

Required. The name of an XML document variable which was set in the previous step of the same process. If this step is the first step, this variable is the body of the SOAP request that is sent to the process engine web service.

Type: String

gel:setDocument - Passing XML Documents

Use this tag to pass an XML document that was generated in one step of a process to the next step. This allows you to write the processing logic in separate steps.

For example, you can invoke one web service, save the response in a step, then retrieve it and use it to invoke XOG in another step.

var

Required. The name of an XML document variable which is to be passed to the next step in the same process.

Type: String

gel:persist - Persisting Variables

When you set a variable in a GEL script, you can only use it when executing that script. Sometimes when the GEL script is executed in a process engine, you need to share a value in other scopes such as:

You can access a persisted value with a PROCESS scope using scripts from that process (even if the process, its steps, and GEL scripts change). If a process is deleted and then recreated, it is considered to be a new process and all values persisted before with PROCESS scope are not available to the new process (even if the new process has the same process name, code, or steps as the deleted one).

var

Required. The variable to be persisted.

Type: String

value

Optional. The value of the variable. It has to be a string (formatted date strings are acceptable). When this attribute is not set, the tag content is used as the value to be persisted. If the value being persisted contains special characters, such as a new line, do not use this attribute, use the text content instead.

Maximum Length: 4000 characters. Longer strings are truncated.

Type: String

scope

Required. Specifies the scope of the variable.

Values:

Type: String

Example

The following example persists the Clarity built-in variables gel_objectInstanceId and gel_processInstanceId throughout this process instance as myObjectId and myProcessId.

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:persist var="myObjectId" value="${gel_objectInstanceId}"
    scope="INSTANCE"/>
  <gel:persist var="myProcessId value="${gel_processInstanceId}"
    scope="INSTANCE"/>

</gel:script>

gel:notify - Sending Notifications

Use this tag to send email. The email content is the text content of this tag, followed by process messages logged thus far during the current process.

Email server information is derived from the properties.xml file of the installation.

from

Required. The sender's email address.

Type: String

fromName

Optional. The name of the sender.

Type: String

to

Required. The recipients' email addresses (delimited by commas, semicolons, or spaces).

Type: String

subject

The email subject.

Type: String

level

Optional. Set this to:

If this attribute is not specified, email is sent no matter how many log messages are retrieved. All process messages logged thus far are included.

Type: String

Example

This example sends a notification if an error had been logged with <gel:log>.

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:notify from="username@mailserver.com"
    fromName="Clarity Admin"
    to="user@somedomain "
    subject="There was a process error"
    level="ERROR">
    A process error was received.
  </gel:notify>

</gel:script>

gel:email - Sending Email Messages

Use this tag to send an email. The email content is the text content of this tag. Email server information is derived from the properties.xml of the installation.

from

Required. The sender's email address.

Type: String

fromName

Optional. The sender's name.

Type: String

to

Required. The recipients' email addresses (delimited by commas, semicolons, or spaces).

Type: String

subject

Required. The email subject.

Type: String

Example

This example sends a simple email:

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:email from="username@mailserver.com"
    fromName="Clarity Admin"
    to="user@somedomain "
    subject="Simple email">
    Hello World.
  </gel:email>

</gel:script>

gel:formatDate - Formatting Time Strings

This tag provides a formatted time string which one can used as a part of a file name, appended to a comment line, or inserted into a database. The following example:

<gel:out>Hello World!  Now it is <gel:formatDate format=" h 'o''clock' a, zzzz, d MMM yyyy"/>.</gel:out>

generates the following output:

Hello World!  Now it is 4 o'clock PM, Pacific Standard Time, 24 Mar 2005.

This tag has the following attributes:

format

Optional. Specifies how time displays in java.text.SimpleDateFormat format.

Note: Go to http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Default: yyyy-MM-dd HH:mm:ss

Type: String

stringVar

Optional. This variable refers a formatted date string. If this attribute is not set, the formatted string is used in the content of this tag's parent element.

Type: String

dateVar

Optional. The variable, of type java.util.Date, referred to by this name is formatted as a string. If this attribute is not set, the current time is used.

Type: String

Example 1

This example formats the current date and time into the format the XOG requires for investment start/finish dates.

<gel:script 
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:out>
    <gel:formatDate format="yyyy-MM-dd'T'HH:mm:ss"/>
  </gel:out>

</gel:script>

Example 2

This example formats the specified date and time into the format the XOG requires for investment start/finish dates. Notice the use of the Java class java.util.Date and the <core:new>, <core:invoke> and <core:arg> tags.

<gel:script 
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <core:new className="java.util.Date" var="date"/>
  <core:invoke on="${date}" method="parse">
    <core:arg value="2009/03/27"/>
  </core:invoke>

  <gel:out>
    <gel:formatDate format="yyyy-MM-dd'T'HH:mm:ss"
      dateVar="date"/>
  </gel:out>

</gel:script>

gel:parseDate - Parsing Time Strings

This tag takes a formatted string, then generates a date instance.

This tag uses the following attributes:

format

Optional. Indicates how the string is formatted in java.text.SimpleDateFormat format.

Note: Go to http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Default: yyyy-MM-dd HH:mm:ss

Type: String

stringVar

Optional. This variable refers to the string to be parsed. If the string does not have the format specified by the format attribute, a parsing exception is thrown.

If this attribute is not set, the text content of this tag is used as the string.

Type: String

dateVar

Required. The parsed date is stored as a java.util.Date and referred to by this variable name.

Type: String

Example

This example parses a date from a string, then formats that date using <gel:formatDate>.

<gel:script 
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:parseDate dateVar="date" format="yyyy-MM-dd">2009-03-27</gel:parseDate>
  
  <gel:out>
My date was: <gel:formatDate format="yyyy-MM-dd'T'HH:mm:ss"
      dateVar="date"/>
  </gel:out>

</gel:script>

gel:setDataSource - Specifying Data Sources

Use this tag to identify the CA Clarity PPM database.

<gel:setDataSource dbId="niku"/>

When you access the CA Clarity PPM database, you only need to know its database ID (that is, you do not need to provide other access information such as username).

This tag uses the following attribute:

dbId

Required. The database ID.

Type: String

gel:nsqlQuery - Executing NSQL Queries

This tag allows you execute an existing NSQL query, or define a new ad-hoc query on the fly to retrieve data from the database, storing the results to the specified variable.

Examples

<gel:setDataSource dbId="niku" var="dataSource"/>

<gel:nsqlQuery queryId="usercountbylicensetype" var="resultSet">
   <gel:nsqlParameter name="license_wildcard" value="*"/>
</gel:nsqlQuery>
<core:forEach items="${resultSet}" var="row">
  <gel:out>Row Contents: '${row}'.</gel:out>
</core:forEach>

<gel:nsqlQuery var="resultSet">
  <![CDATA[
  SELECT   @SELECT:U.USER_NAME:USER_NAME@,
           @SELECT:U.ID:USER_ID@
  FROM     CMN_SEC_USERS U
  WHERE    @FILTER@ ]]>
  <gel:nsqlParameter name="user_name_wildcard" value="admin*"/>
</gel:nsqlQuery>
<core:forEach items="${resultSet}" var="row">
  <gel:out>Row Contents: '${row}'.</gel:out>
</core:forEach>

gel:log - Logging Messages

Use this tag to insert status messages into the process engine log table.

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <gel:log level="warn" category="Employee Data" 
    message="No record returned."/>

</gel:script>

This tag logs messages as a process message in the BPM_ERRORS table when this script runs as a custom step in a process. If the process is running from the console, the message is inserted into the standard log file.

message

Optional. The messaged to log. The message can be set as a value attribute or as the content of this tag.

Type: String

category

Optional. Use this to distinguish logs. It can be concatenated from business data type, file name, developer ID, etc.

Type: String

level

Optional. This is the warning level. Choose from the following:

This attribute is not case sensitive. For example, WARN, warn, and Warn are the same.

A process message has only three levels: INFO, WARNING, and ERROR, while a logger message in the log file can have all levels. When a message is logged as a process message, DEBUG and INFO messages are logged as INFO messages, WARN messages are logged as WARNING messages, and ERROR and FATAL messages are logged as ERROR messages.

Default: INFO

Type: Level

var

Optional. A variable name into which the log message should be stored. Use this when you want to save log messages for other purposes such as sending emails.

If the variable is:

Type: String

gel:out - Printing to the Console

This tag prints the content of this tag to the system console. It does not have any attributes.

Use this tag only when you are using the console to debug and the GEL script is not running as a process. For example,

<core:set var="x" value="file.rows[2][3]"/>
	<gel:out>${x}</gel:out>

If you have a variable that contains an XML Node, including an XML document and you want to print it, combine gel:out with gel:expr:

<gel:parse var="doc">
	<groups>...</groups>
</gel:parse>
<gel:out><gel:expr select="$doc/groups"/></gel:out>

Core Tag Library

The tags in this section are a useful subset of the jelly:core tag library. Go to http://jakarta.apache.org/commons/jelly/tags.html for Jakarta Jellytag descriptions.

The following additional tags can invoke Java class methods directly:

The following tags are also are useful for controlling flow in your script:

Include the following namespace declaration in your script to use this tag library:

<gel:script   xmlns:core="jelly:core"...>

core:catch - Catching Exceptions

Use the Jelly fault-handling tags to catch exceptions and exit gracefully when a process failure occurs. Use the <j:catch> tag to capture exceptions in the ex variable. Outside of the catch tags, you can check the ex variable and write it to the console using gel:out.

Example

<gel:script
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <!-- this gel:set will throw an exception -->
  <core:catch var="exception">
    <gel:set select="$bad/text()" var="mynode"/>
  </core:catch>
  
  <core:if test="${exception != null}">
    <gel:out>Caught Exception was:
    ${exception}</gel:out>
  </core:if>

</gel:script>

core:set - Setting Variables

This sets a variable from the result of an expression.

defaultValue

Sets the default value to use if the value expression results in a null value or blank string.

Type: org.apache.commons.jelly.expression.Expression

encode

When set to:

“1”, the body of the tag is encoded as XML text. When "<" and ">" are encountered in the tag body, they are encoded as "&lt;" and "&gt;".

“0”, the body is not encoded.

Use this only if this tag is specified with no value so that the text body of this tag can be used as the body.

Type: Boolean

escapeText

When set to:

“1”, the body of the tag is escaped (interpreted as text).

“0”, the body is interpreted as XML.

Default: “1” (text)

Type: Boolean

property

Indicates the property name to set on the target object.

Type: java.lang.String

scope

Sets the scope of this variable. For example when set to "parent", this value is in the parent scope. When Jelly is run from inside a servlet then other scopes are available such as "request", "session", or "application".

Other applications may implement their own scopes.

Type: java.lang.String

target

Sets the target object on which to set a property.

Type: java.lang.Object

trim

When set to:

“1”, whitespace inside this tag is trimmed.

“0”, whitespace is not trimmed.

Default: “1” (trimmed).

Type: Boolean

value

Sets the expression to evaluate.

Type: org.apache.commons.jelly.expression.Expression

var

Sets the variable name to define for this expression.

Type: java.lang.String

Example

This example shows setting strings and numbers.

<gel:script
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <core:set var="color" value="blue"/>
  <gel:out>Color is ${color}</gel:out>

  <core:set var="age" value="39"/>
  <gel:out>My age is ${age - 18}</gel:out>

</gel:script>

core:forEach - Iterating over Elements

This iterates over elements. It has the following attributes:

begin

Sets the starting index value (for first element in the array).

Type: int

end

Sets the last index value.

Type: int

escapeText

When set to:

Default: 1

Type: Boolean

indexVar

Sets the variable into which the current index counter is exported.

Type: java.lang.String

items

Sets the expression used to iterate over. This expression may resolve to an iteration, collection, map, array, enumeration, or comma-delimited string.

Type: org.apache.commons.jelly.expression.Expression

step

Sets the index increment step.

Type: int

trim

Values:

Default: 1

Type: Boolean

var

Sets the variable into which the item being iterated over.

Type: java.lang.String

varStatus

Sets the variable into which the current status is exported. The status is an implementation of the JSTL LoopTagStatus interface that provides the following bean properties:

Type: java.lang.String

Example

This example iterates through the properties in the file test.properties that ships with the XOG client and prints out each property.

<gel:script
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">
  <!-- print out each value we find -->
  <core:forEach items="A, B, C, 1, 2, 3" var="value">
    <gel:out>Value = ${value}</gel:out>
  </core:forEach>
</gel:script>

core:if - Evaluating Conditionally

This tag evaluates the body based on some condition.

This tag has the following attributes:

escapeText

When set to:

Default: 1

Type: Boolean

trim

When set to:

Default: 1.

Type: Boolean

test

Sets the Jelly expression to evaluate. If this returns true, the body of the tag is evaluated.

Type: org.apache.commons.jelly.expression.Expression

Example 1

This example tests the value of a variable in a <core:if> statement.

<gel:script
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <core:set var="color" value="blue"/>
  
  <core:if test="${color == 'blue'}">
    <gel:out>Color matched blue!</gel:out>
  </core:if>

</gel:script>

Example 2

This example tests the numeric value. Notice that the > symbol has been escaped in the XML as > is a reserved character.

<gel:script
  xmlns:core="jelly:core"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">

  <core:set var="age" value="10"/>
  
  <core:if test="${age &gt; 5}">
    <gel:out>Age is greater than 5</gel:out>
  </core:if>

</gel:script>

SOAP Tag Library

Use the XML SOAP tags in this section to invoke a SOAP-based external or internal web service such as the XOG API.

Include the following namespace declaration in your script to use this tag library:

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.SOAPTagLibrary">

soap:invoke - Invoking SOAP Web Services

Use this tag to invoke a web service at a specified endpoint and assign a name to the resulting XML document. You can use subsequent tags to access the tag's variables and extract data from the document. The invoke tag can contain sub-tags, including soap:envelope and soap:attachment.

This tag has the following attributes:

endpoint

Required. Specifies either the keyword 'internal' or the URL of the web service to be invoked.

Values:

Type: String

var

Optional. Contains the response from the web service. The response is of type org.w3c.dom.Document.

Type: String

This tag has the following subtags:

Example

<soap:invoke endpoint=”internal” var=”result”>
  <soap:message>...</soap:message>
</soap:invoke>

<soap:invoke endpoint=”${serviceUrl}” var=”result”>
  <soap:message>...</soap:message>
</soap:invoke>

soap:envelope - Generating a SOAP Envelope

This tag generates a SOAP envelope which can be used by soap:invoke to send a SOAP request. It includes the following header and body tags:

soap:header - Specifying the SOAP Header

This tag contains the SOAP header, which should be included in a SOAP envelope. You choose which data to include.

soap:body - Specifying the SOAP Body

This tag controls the SOAP body (which should be included in a SOAP envelope). You can control which data to include. You can write content into this tag as illustrated in SOAP Examples, or you can write content as an attribute of this tag as illustrated in the following example.

This tag has the following attribute:

xml

Optional. Sets the source of the soap:body. If this attribute is set, the content of the document variable, which can be set by gel:parse or ftp:get, is used as the content of this soap:body tag (and the body of this tag is ignored). If there is an XML file you want to use as the content of SOAP body, use gel:parse to read the file and set this attribute.

Type: org.w3c.dom.Document

Example

This example executes an NSQL query through the XOG web service and writes the results to a tab-delimited file.

  <gel:script
  xmlns:core="jelly:core"
  xmlns:xog="http://www.niku.com/xog"
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
  xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:f="jelly:com.niku.union.gel.FileTagLibrary"
  xmlns:nikuq="http://www.niku.com/xog/Query"

  <!-- Construct the Query API request for the NSQL query
    "xog_query_test" -->
  <gel:parse var="xoginput">
    <Query xmlns="http://www.niku.com/xog/Query">
      <Code>cats.resourceProfile</Code>
    </Query>
  </gel:parse>

  <soap:invoke endpoint="internal" var="xogresponse">
    <soap:message>
      <soapenv:Envelope>
        <soapenv:Header>
          <Auth>
            <Username>admin</Username>
            <Password>niku2000</Password>
          </Auth>
        </soapenv:Header>
        <soapenv:Body>
          <gel:include select="$xoginput"/>
        </soapenv:Body>
      </soapenv:Envelope>
    </soap:message>
  </soap:invoke>

  <!-- Extract the sessionID so we may logout later -->
  <gel:set asString="true"
    select="$xogresponse//xog:SessionID/text()" 
    var="sessionID"/>
  <gel:out>SessionID = ${sessionID}</gel:out>

  <!-- Extract the records -->
  <gel:set select="$xogresponse//nikuq:QueryResult/nikuq:Records"
    var="records"/>

  <!-- Create a tab-delimited file from the results -->
  <f:writeFile fileName="projectData.txt" 
    delimiter="&#x9;" embedded="true">
  <gel:forEach select="$records//nikuq:Record" var="xog_record">
    <f:line>
    <gel:forEach select="$xog_record/*" var="xog_data">
      <gel:set var="xog_data" select="$xog_data/text()"
        asString="true"/>
      <f:column value="${xog_data}"/>
    </gel:forEach>
    </f:line>
  </gel:forEach>
  </f:writeFile>

  <!-- Now log out -->
  <soap:invoke endpoint="internal" var="logout">
    <soap:message>
      <soapenv:Envelope>
        <soapenv:Header>
          <Auth>
            <xog:SessionID>${sessionID}</xog:SessionID>
          </Auth>
        </soapenv:Header>
      <soapenv:Body>
        <xog:Logout/>
      </soapenv:Body>
    </soapenv:Envelope>
  </soap:message>
  </soap:invoke>

  <gel:out>Output written to projectData.txt</gel:out>

</gel:script></gel:script>

More information:

Example: Execute External Web Services with Attachments

soap:attachment - Attaching Files to SOAP Requests

This tag specifies the file to be attached in the SOAP request.

This tag has the following attributes:

dir

Required. The directory on the local disk where the attachment file is located.

Type: String

fileName

Required. The file to be attached with the SOAP request.

Type: String

Example

<soap:attachment dir=”${dir} “ fileName=”${file}”/>

soap:message - Specifying SOAP XML Messages

The tag contains the actual SOAP XML message. This includes the SOAP envelope, header and body tags.

Example

<soap:message>
<obj:ReadGroup xmlns:obj="http://www.niku.com/xog/Object">
  <DataBus xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” 
           xsi:noNamespaceSchemaLocation=”../xsd/xog_read.xsd”>
    <xog:Header version=”7.5” 
      externalSource=”NIKU”/>
        <xog:Query>
          <xog:Filter name=”code” criteria=”OR”>
               ProjectManager,PortfolioManager,XOGTestGroup
          </xog:Filter>
        </xog:Query>
      </xog:DataBus>
    </obj:ReadGroup>
  </xog:processRequest>
</soap:message>

Example: XOG Login and Read Objects Example

<gel:script 
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
  xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xog="http://www.niku.com/xog">
  
<soap:invoke endpoint="internal" var="auth">
  <soap:message>
    <soapenv:Envelope>
      <soapenv:Header>
	<Auth xmlns="http://www.niku.com/xog">
          <Username>admin</Username>
          <Password>clarity</Password>
        </Auth>
      </soapenv:Header>
      <soapenv:Body/>
    </soapenv:Envelope>
  </soap:message>
</soap:invoke>

<soap:invoke endpoint="internal" var="result">
  <soap:message>
    <soapenv:Envelope>
      <soapenv:Header>
        <Auth>
          <xog:SessionID>
            <gel:expr select="$auth//xog:SessionID/text()"/>
          </xog:SessionID>
	</Auth>
      </soapenv:Header>
      <soapenv:Body>
      <obj:ReadGroup 
        xmlns:obj="http://www.niku.com/xog/Object">
        <NikuDataBus 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:noNamespaceSchemaLocation="../xsd/xog_read.xsd">
          <Header version="7.5" externalSource="NIKU"/>
          <Query>
            <Filter name="code" criteria="OR">
              ProjectManager,PortfolioManager,XOGTestGroup
            </Filter>
          </Query>
        </NikuDataBus>
      </obj:ReadGroup>
      </soapenv:Body>
    </soapenv:Envelope>
  </soap:message>
</soap:invoke>

<soap:invoke endpoint="internal" var="auth">
  <soap:message>
    <soapenv:Envelope>
      <soapenv:Header>
        <Auth>
          <xog:SessionID>
            <gel:expr select="$auth//xog:SessionID/text()"/>
          </xog:SessionID>
        </Auth>
      </soapenv:Header>
      <soapenv:Body>
        <xog:Logout/>
      </soapenv:Body>
      </soapenv:Envelope>
  </soap:message>
</soap:invoke>

</gel:script>

Example: Execute External Web Services with Attachments

The following example places the XOG output as an XML document in the variable result. This example uses a hypothetical external web service "UploadFile."

<gel:script
  xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
  xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
  xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
>
<soap:invoke endpoint="${serviceUrl}" var="result">
  <soap:message>
    <soap-env:Envelope>
      <soap-env:Header>
        AuthId>${authId}</AuthId>
        <Locale>en_US</Locale>
      </soap-env:Header>
      <soap-env:Body>
        <UploadFile xmlns="xxx">
          <NewFile>
              <Name>/${file}</Name>
            <ReplaceExisting>true</ReplaceExisting>
          </NewFile>           
        </UploadFile>
      </soap-env:Body>
    </soap-env:Envelope>
  </soap:message>
  <soap:attachment dir="${dir}" fileName="${file}"/>
</soap:invoke>
<gel:out>Out: <gel:expr select="$result"/></gel:out>
</gel:script>