自 2021 年 1 月起,经典文件类型不再可用。您可以转换经典文件或下载 PDF 文件。了解更多

Unable to get the Environment Variable from Triggering a Run in Automation

0

评论

5 条评论

  • 正式评论
    Brett Harper

    Hi, try specifying an "Input section" too, even if your script does not require it, then you should get the envvars you are expecting.

  • Jase the Ace

    Hi Brett,

    This is what I got back with a random sheet being selected:

    RAW parameters:
    environ({'WORKIVA_ORGANIZATION_ID': '${WORKIVA_ORGANIZATION_ID}', 'WORKIVA_ACCOUNT_ID': '${WORKIVA_ACCOUNT_ID}', 'WORKIVA_CLUSTER_DOMAIN': '${WORKIVA_CLUSTER_DOMAIN}', 'DOCUMENT_ID': '${DOCUMENT_ID}', 'INPUT_RESOURCE_ID': 'wurl://sheets.v0/0:sheets_${DOCUMENT_ID}/1:sheets_${DOCUMENT_ID}_${INPUT_SPREADSHEET_SHEET_ID}', 'INPUT_SHEET_ID': 'wurl://sheets.v0/0:sheets_${DOCUMENT_ID}', 'INPUT_SPREADSHEET_ID': '${DOCUMENT_ID}', 'INPUT_SPREADSHEET_SHEET_ID': '${INPUT_SPREADSHEET_SHEET_ID}', 'LC_CTYPE': 'C.UTF-8'})
    
    Actual IDs:
    ${DOCUMENT_ID}
    ${INPUT_SPREADSHEET_SHEET_ID}

    Is the same python code above.

    0
  • Brett Harper

    Yep, that is expected.  The values of those envvars are redacted when printed to the log, but they are available to your code to use.  To verify you can call the FilesAPI with that INPUT_SPREADSHEET_SHEET_ID and you will get the file info for that Spreadsheet. 

    0
  • Jase the Ace

    Got it, I thought there was something wrong but I am able to have it going now.

    I do have a follow-up question but is related to using the api call to refresh a connection. I am trying to refresh an outgoing connection from a spreadsheet sheet to a wdata table, it doesn't have any parameter, I used the refresh connection call with the body as following:

            body = {  
                "connectionId": connection_id,  
                "destinationParameters": {},  
                "sourceParameters": {},  
                "usePreviousDestinationParameters": False,  
                "usePreviousSourceParameters": False,  
                "workspaceId": workspace_id  
            }  
     
    The API call triggered the refresh but it failed and returned a bad request. Is there something wrong with my body? 
    0
  • Brett Harper

    I'm not sure exactly what the issue is, but you could try setting the fileName that will end up being the name of the .csv dataset that you import into the wdata table.

    connections = wdata_api.get_connections(source_id=spreadsheet_id, source_type="spreadsheet")
    my_connection = connections[0]   # iterate to find the right connection if needed
    assert(connection.get("destinationType") =="wdata_table")
     
    connection_id=connection.get("connectionId")
    wdata_table_id=connection.get("destinationId")
    dataset_filename=f"{dataset_name}.csv"
     
    refresh_connection_dto = { "connectionId": connection_id, "destinationParameters": {"fileName": dataset_filename}, "sourceParameters": {} }

    If there was already a file imported into that wdata table that has the same name but from a different connection, you will get a conflict, so you may need to also check for existing datasets and programmatically remove them like this:
     
    table_files = wdata_api.get_table_files(wdata_table_id)
    existing_table_file = APIUtils.item_in_object_list(table_files, "name", dataset_filename)
    table_file_id = existing_table_file.get("id")
    wdata_api.unimport_file(wdata_table_id, table_file_id, delete_file=True)
     
    0

请先登录再写评论。