rpaframework icon indicating copy to clipboard operation
rpaframework copied to clipboard

RPA.Tables needs keyword to easily transfer it in work items

Open orlof opened this issue 1 year ago • 1 comments

Current solution requires this kind of code:

    # STEP 1

    # create a table for testing
    ${files}=    List files in directory    ${CURDIR}
    ${table}=    Create table    ${files}

    # export table to list of dicts
    ${export}=    Export table    ${table}
    # transform to JSON string
    ${json_str}=    Evaluate    json.dumps($export)    modules=json

    # HERE WOULD BE THE WORK ITEM TRANSFER

    # STEP 2

    # transform JSON string back to list of dicts
    ${json}=    Evaluate    json.loads($json_str)    modules=json
    # reconstruct the table from list of dicts
    ${table2}=    Create Table    ${json}
    Log    ${table2.columns}

We need to design a single keyword solution.

orlof avatar Mar 27 '23 07:03 orlof

RPA.JSON library has keywords:

Convert JSON to string
Convert string to JSON

Those should do the trick without evaluating python:

Producer
    # create a table for testing
    ${files}=    List files in directory    ${CURDIR}
    ${my_table}=    Create table    ${files}

    Create output work item
    ${my_table}=    Export table    ${my_table}
    ${my_table}=    Convert JSON to string    ${my_table}
    Set work item variable    my_table    ${my_table}
    Save work item

Consumer
    ${my_table}=    Get work item variable    my_table
    ${my_table}=    Convert string to JSON    ${my_table}
    ${my_table}=    Create table    ${my_table}

By far the best user experience would be to allow Tables directly in Get work item variable and Set work item variable -keywords. The previous example would become:

Producer
    # create a table for testing
    ${files}=    List files in directory    ${CURDIR}
    ${my_table}=    Create table    ${files}

    Create output work item
    Set work item variable    my_table    ${my_table}
    Save work item

Consumer
    ${my_table}=    Get work item variable    my_table

orlof avatar Mar 29 '23 07:03 orlof