Robocorp Work Items

1.5.0 · active · verified Thu Apr 16

The `robocorp-workitems` library is part of the Robocorp ecosystem, providing utilities to manage data flow between tasks in a Robotic Process Automation (RPA) workflow. It allows robots to read input work items and write output work items, facilitating the transfer of structured data, files, and assets. The current version is 1.5.0, and it's actively maintained as part of the broader Robocorp platform.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to read data from an input work item and create an output work item with a new payload. It's designed to run within the Robocorp environment or locally with simulated work item data.

from robocorp.tasks import task
from robocorp.workitems import inputs, outputs

@task
def process_data():
    # Read current input work item's payload
    input_item = inputs.current
    if input_item.get_payload('my_key'):
        data = input_item.get_payload('my_key')
        print(f"Received data: {data}")
    else:
        print("No 'my_key' found in input payload. Using default.")
        data = {"message": "Hello from robot!"}

    # Create an output work item
    output_item = outputs.create()
    # Add a payload to the output work item
    output_item.set_payload({"status": "processed", "original_data": data})
    # You can also add files
    # output_item.add_file('path/to/my_file.txt')
    # Save the output work item
    output_item.save()

    print("Output work item created and saved.")

view raw JSON →