Unable to get the Environment Variable from Triggering a Run in Automation
Hi, I am trying to use the built in automation to feed spreadsheet id to a script. I had a script set up to run the script listed in the documentation https://support.workiva.com/hc/en-us/articles/9869574493460-Execute-scripts-with-automations to see what it returns, but looks like I am missing something, the result didn't return an actual spreadsheet id back.
Here's how I configure the automation:
Here's what the script return:
-
正式なコメント
Hi, try specifying an "Input section" too, even if your script does not require it, then you should get the envvars you are expecting.
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.
0Yep, 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.
0Got 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?0I'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 neededassert(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サインインしてコメントを残してください。
コメント
5件のコメント