Skip to main content
Version: 10.2.8

Apply WebHarvest and WorkFusion context variables

In Bot Configs, you have access to both WebHarvest and WorkFusion context variables. The Manual Task context is described in the Manage templates topic.

WebHarvest context

Every WebHarvest variable context initially contains the following help objects you can use in any expression inside configurations.

Object sys

The sys object contains general-purpose constants and methods.

NameDescription
sys.lfLine feed character (\n).
sys.crCarriage return character (\r).
sys.tabTab character (\t).
sys.spaceSpace character ( ).
sys.quotDouble quote character (").
sys.aposSingle quote character (').
sys.backspaceBackspace character (\b).
sys.date()Returns the current date in the yyyyMMdd format.
sys.time()Returns current time in the HHmmss format
sys.datetime(format)Returns the date and time in specified format. Use Java date and time formatting patterns.
sys.escapeXml(text)Escapes the &'"<> characters in the specified text according to the XML standard.
sys.fullUrl(pageUrl, link)For the specified web page URL and link (relative, absolute, or full URL) returns the full URL.
sys.defineVariable(varname, varvalue, [overwrite])Defines a new variable with the specified name and value in the current WebHarvest context. The overwrite parameter tells whether to overwrite the existing variable with the same name. Its default value is true. It has the same meaning as the var-def processor. However, it can be useful for value exchange between scripts and the WebHarvest context.
sys.isVariableDefined(varname)Tells if the variable with the specified name is defined in the context.
sys.getVar(varname)Returns the variable from the scraper context.
sys.xpath(xpathexpr, xml)Evaluates the XPath expression in the specified XML. Returns the oforg.webharvest.runtime.variables.Variable class instance.

For more details, check the Java API for class.

Object http

The http object provides access to the HTTP client and gives information about HTTP responses:

NameDescription
http.clientReturns an instance of the org.apache.commons.httpclient.HttpClient class used as the primary HTTP client during the configuration execution. For more details, see the Jakarta HttpClient documentation.
http.contentLengthLenght of the last HTTP response content in bytes.
http.charsetEncoding of the last HTTP response if it contains textual content.
http.mimeTypeMime type of the last HTTP response.
http.headersArray of the HTTP response header pairs. To access an individual header by the index, use http.headers.length, http.headers[index].key, and http.headers[index].value. To access the first header value by the name, use http.getHeader("headername"). To get all headers with a specified name, use http.getHeaders("headername"): http.getHeaders("Set-Cookie").length and http.getHeaders("Set-Cookie")[index].
http.statusCodeStatus code of the last HTTP response.
http.statusTextStatus message of the last HTTP response.
http.totalLengthTotal length in bytes of all responses returned to this HTTP client.
http.totalResponsesTotal number of responses returned to this HTTP client.

Object log

The log object provides the ability to print debug information. The logger object is of the org.slf4j.Logger type and supports all methods of the type:

  • log.info(message) prints a specified message.

  • log.error(message, exception) prints a specified message along with the exception stack trace.

  • log.debug(messageTemplate, argument) formats and prints a specified message template with the passed argument. For example, log.debug("Number of objects received: {}", receivedObjects.size()).

For more details, refer to org.slf4j.Logger.

WorkFusion context

In a WebHarvest XML configuration, you can use and access a set of defined variables and their types:

  • hit_submission_data_item (Object) contains the current hit submission data item. CLASS: com.freedomoss.crowdcontrol.webharvest.HitSubmissionDataItemDto.
  • item (Object) is a WebHarvest task item. Contains necessary information about the run, submission, and other objects. CLASS: com.freedomoss.crowdcontrol.webharvest.WebHarvestTaskItem.
  • prevData (Object) is a WebHarvest task item. Contains necessary information about the run, submission, and other objects. CLASS: com.freedomoss.crowdcontrol.webharvest.PreviousData.
  • assignment (Object) is the current assignment. CLASS: com.freedomoss.crowdcontrol.webharvest.AwsHitAssignmentDto.
  • source (Object) is the current source. CLASS: com.freedomoss.crowdcontrol.webharvest.SourceDto.
  • dataStoreProperties (Object). CLASS: com.freedomoss.crowdcontrol.webharvest.web.security.DatabaseProperties.
  • includedConfigs (Map) is a map of included configs. Used in the include-config plugin. Map<String, String>: key is the config name, value is the config body.
  • applicationHost (String) is the WorkFusion host name.
  • applicationContextPath (String) is the WorkFusion context path.
  • applicationResourceUrl (String) is the root URL for resources. Default: https://s3.amazonaws.com.
  • userInternalCredentials (Object) is the username and hashed password (a hashed value fetched from the database) of the user who executes the current run (Run.createdBy). Contains only the username of the task author and an empty string password. It is not recommended to use the object.
  • seleniumDriver (Object).
  • seleniumServer (Object).
  • seleniumLogger (Object).
  • seleniumDriverRegistry (Object).
  • selenium_node_id (Object).
  • selenium_parent_browser_capabilities (String).
  • capabilityNodeId (String).
  • exportResult (Object).
  • releaseDate (Object).
  • s3EndpointUrl (String).
  • s3AccessKey (String).
  • s3SecretKey (String).
  • s3KeyMap (Map).
  • secureStorePassword (String).

Usage examples

To access WorkFusion variables in a Bot Config, use the getWrappedObject() method. See the reference.

For descriptions of all Classes and DTOs (data transfer objects) accessible in Bot Configs, refer to javaDoc.

Example of accessing the WorkFusion context variables from Bot Config:

<script>
<![CDATA[
int processingAttempts = item.getWrappedObject().getSubmission().getAwsHit().getProcessingAttempts();
Integer maxAttempts = item.getWrappedObject().getRun().getMaxProcessingCount();
//...
]]>
</script>

<!-- Generate a link to current BP instance (run) -->

<export include-original-data="true">
<single-column name="link" value="${applicationHost}/workfusion/secure/business-process/edit/${item.getWrappedObject().getRun().getRootRunUuid()}" />
</export>
troubleshooting