Apply WebHarvest and WorkFusion context variables
In Bot Configs, you have access to both Web-Harvest and WorkFusion context variables. The Manual Task context is described in the Manage templates topic.
WebHarvest context
Every Web-Harvest 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.
sys.lf |
Line feed character (\n). |
sys.cr |
Carriage return character (\r). |
sys.tab |
Tab character (\t). |
sys.space |
Space character ( ). |
sys.quot |
Double quote character ("). |
sys.apos |
Single quote character ('). |
sys.backspace |
Backspace 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 date and time in specified format. Use Java date and time formatting patterns. |
sys.escapeXml(text) |
Escapes characters &'"<> in the specified text according to 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 Web-Harvest context. The Its default value is |
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 the class.
Object http
The http object provides access to the HTTP client and gives information about HTTP responses:
http.client |
Returns the For details, see Jakarta HttpClient documentation. |
http.contentLength |
Lenght of the last HTTP response's content in bytes. |
http.charset |
Encoding of the last HTTP response if it contains textual content. |
http.mimeType |
Mime type of the last HTTP response. |
http.headers |
An array of the HTTP response header pairs. To access an individual header by index, use:
To access the first header value by the name, use:
To get all headers with the specified name, use
|
http.statusCode |
Status code of the last HTTP response. |
http.statusText |
Status message of the last HTTP response. |
http.totalLength |
Total length in bytes of all responses returned to the HTTP client. |
http.totalResponses |
Total number of responses returned to the 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 the specified message. |
log.error(message, exception) |
Prints the specified message along with the exception stack trace. |
log.debug(messageTemplate, argument) |
Formats and prints the specified message template with the passed argument, аor example, log.debug("Number of objects received: {}", receivedObjects.size()). |
| and many more... | Refer to org.slf4j.Logger. |
WorkFusion context
In the Web-Harvest 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 Web-Harvest task item. Contains necessary information about the run, campaign, submission, and other objects. CLASS: com.freedomoss.crowdcontrol.webharvest.WebHarvestTaskItem.prevData(Object) is a Web-Harvest task item. Contains necessary information about the run, campaign, submission, and other objects. CLASS: com.freedomoss.crowdcontrol.webharvest.PreviousData.assignment(Object) is the current assignment. CLASS: com.freedomoss.crowdcontrol.webharvest.AwsHitAssignmentDto.source(Object): current source. CLASS: com.freedomoss.crowdcontrol.webharvest.SourceDto.dataStoreProperties(Object). CLASS: com.freedomoss.crowdcontrol.webharvest.web.security.DatabaseProperties.includedConfigs(Map) is the 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.comuserInternalCredentials(Object) is the username and hashed password (a hashed value fetched from 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
Each WorkFusion variable is accessible in the Bot Config using 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 the 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>