{"id":7682,"library":"robocorp-workitems","title":"Robocorp Work Items","description":"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.","status":"active","version":"1.5.0","language":"en","source_language":"en","source_url":"https://github.com/robocorp/robocorp/tree/master/packages/workitems","tags":["robocorp","rpa","automation","work-items","workflow","data-exchange"],"install":[{"cmd":"pip install robocorp-workitems","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Provides access to the current work item (input or output).","symbol":"current","correct":"from robocorp.workitems import current"},{"note":"Module for accessing input work items.","symbol":"inputs","correct":"from robocorp.workitems import inputs"},{"note":"Module for creating and managing output work items.","symbol":"outputs","correct":"from robocorp.workitems import outputs"},{"note":"The older `RPA.Robocorp.WorkItems` from `rpaframework` is deprecated in favor of `robocorp.workitems`.","wrong":"from RPA.Robocorp.WorkItems import WorkItems","symbol":"WorkItems","correct":"from robocorp.workitems import current"}],"quickstart":{"code":"from robocorp.tasks import task\nfrom robocorp.workitems import inputs, outputs\n\n@task\ndef process_data():\n    # Read current input work item's payload\n    input_item = inputs.current\n    if input_item.get_payload('my_key'):\n        data = input_item.get_payload('my_key')\n        print(f\"Received data: {data}\")\n    else:\n        print(\"No 'my_key' found in input payload. Using default.\")\n        data = {\"message\": \"Hello from robot!\"}\n\n    # Create an output work item\n    output_item = outputs.create()\n    # Add a payload to the output work item\n    output_item.set_payload({\"status\": \"processed\", \"original_data\": data})\n    # You can also add files\n    # output_item.add_file('path/to/my_file.txt')\n    # Save the output work item\n    output_item.save()\n\n    print(\"Output work item created and saved.\")","lang":"python","description":"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."},"warnings":[{"fix":"Replace `from RPA.Robocorp.WorkItems import WorkItems` with `from robocorp.workitems import current, inputs, outputs`. Re-implement logic using the new, idiomatic API.","message":"The `robocorp-workitems` library is the modern replacement for the older `RPA.Robocorp.WorkItems` from the `rpaframework`. Direct migration is needed as the API has changed significantly.","severity":"breaking","affected_versions":"All `robocorp-workitems` versions when migrating from `rpaframework`."},{"fix":"Always run your robot using `rc task run` for local development or within Robocorp Control Room for production. For local testing, simulate input work items by creating a `devdata/work-items-in` directory with `work-item.json` files.","message":"The `robocorp.workitems.current` object (and `inputs.current`, `outputs.create()`) relies on a Robocorp execution environment. When running a Python script directly without `rc task run` or a properly configured `devdata` folder, `current` might be `None` or operations might fail.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Ensure all data placed into `set_payload` or `add_payload` consists of standard Python types (dict, list, string, number, boolean, None) that can be directly converted to JSON.","message":"Payloads for work items must be JSON serializable. Attempting to add non-serializable objects (e.g., custom class instances, datetime objects without conversion) directly to the payload will result in a serialization error.","severity":"gotcha","affected_versions":"All versions."}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Execute your robot using `rc task run` or within Robocorp Control Room. For local development, create a `devdata/work-items-in/work-item-1/work-item.json` file to simulate an input work item.","cause":"Attempting to access `current.get_payload()` when `current` is `None`. This typically happens when the `robocorp-workitems` library is used outside a Robocorp task execution context without simulating input data.","error":"AttributeError: 'NoneType' object has no attribute 'get_payload'"},{"fix":"Update your import statements from `from RPA.Robocorp.WorkItems import ...` to `from robocorp.workitems import ...` and refactor your code to use the new API. If you specifically need `rpaframework`, ensure it is installed (`pip install rpaframework`).","cause":"This error indicates that the project is trying to use the deprecated `RPA.Robocorp.WorkItems` library (part of `rpaframework`) while `robocorp-workitems` is installed, or the `rpaframework` is not installed.","error":"ModuleNotFoundError: No module named 'RPA.Robocorp.WorkItems'"},{"fix":"Before setting the payload, convert your custom objects or `datetime` objects into basic Python data structures (e.g., dictionaries, lists, strings) that are JSON serializable (e.g., `dt_object.isoformat()`).","cause":"You attempted to add an instance of a custom Python class, a `datetime` object, or another non-JSON-serializable data type directly into a work item payload.","error":"TypeError: Object of type <YourCustomClass> is not JSON serializable"}]}