I tipi di file classici non potranno più essere utilizzati a partire da gennaio 2021. È possibile effettuare la transizione dei file classici o scaricare un PDF. Ulteriori informazioni

How do I produce a chain output while executing a script on a chain?

0

Commenti

6 commenti

  • Jeff Hickey

    Hi Jeremy. What are both the SSApi() and read_tier_data() functions doing? Which API endpoints are they interfacing with? You could use the csv python module to create the csv file in your script after you're able to populate the data list.

    Are you able to complete these operations within the Chain (eg. Get Sheet Data and Smart Filter Rows commands) prior to executing your script via Script Runner? Keeping these operations within your Chain may help to simplify things unless you have a requirement to run these operations outside of Chains in your script.

    0
  • Jeremy Pond

    Thank you Jeff. I will play around with the csv python module. I am working with a BAI2 banking file, and although it is a csv file, the data is structured in a hierarchy of different record types. For example, the bank account information is not on the same row as the transaction information in the file. I am not familiar with a way to consolidate all of this information into a data set with all data elements in a single row, other than through writing a script. 

    SSApi() fetches the bearer token to include in the header when calling the workiva application API.  

    read_tier_data() is a function that calls the https://api.app.wdesk.com/platform/v1/spreadsheets/ API to read the contents of the spreadsheet with the BAI2 file. This spreadsheet was populated with the contents of the BAI2 file from the overwrite sheet data node which was upstream on the chain.

    Our ERP system is Oracle Cloud Financials, and the API to import the journal entry requires that I send a CSV file formatted to Oracle's specifications. 

    0
  • Jeremy Pond

    I tried writing my dictionary of data to a csv file and I got the following error: 

    # writing to csv file
    with open('journalentry.csv', 'w') as csvfile:
    [...] 

    File "/mnt/__main__.py", line 174, in main
    with open('journalentry.csv', 'w') as csvfile:
    OSError: [Errno 30] Read-only file system: 'journalentry.csv'

    Do we need to specify a network location to produce a csv file? I'm not sure what that would be since this is running in a container on workiva platform. Alternatively, I could write this journal entry data dictionary to a sheet in wdesk, but is there a command to convert a sheet in workiva to create a CSV file from there? The only commands I found to create a CSV file are in the tabular transformation library to convert a JSON to a CSV, and to convert an XLSX file to a csv. Trying to use either of these would require an output from the script node, which brings me back to my original and current issue of producing an output of the script that I can access downstream instead of just showing the output in a log. 

    0
  • Jeff Hickey

    I initially incorrectly assumed you were building your python script outside of Workiva rather than using Workiva Scripting. I'm curious if you have sample data that demonstrates the raw data with the account and transaction information on different rows as well as an example of the final result you've configured your script to produce? If you're able to share an example, please do not include any actual data or values.

    0
  • Jeremy Pond

    Hi Jeff,

    Here is an example of the BAI2 file text with sample data

    01,WPACAU2DK,BHOL,190321,1631,01,080,,2/
    02,BHOL,WPACAU2DK,1,190208,,AUD,2/
    03,11111111111,AUD,010,0,,,015,1200000,,,045,1200000,,,400,2800000,4,,100/
    88,4000000,6,/
    16,354,73835,,,0,Interest Earned
    49,14678000,23/
    98,14678000,1,25/
    99,14678000,1,27/

     

    When I run my script in workiva chains, I am able to produce the list I need, but I am unable to save it as a CSV file. Here is the log details. The first section shows a print() of the list. The second section is a continuation of the log with the error info when I tried to dump the list into a csv file. 

     

    Calling main
    ['190208', '000076856', '', '41.00.100220.000.00000000.00.0000', 738.35, 738.35, '', 'Interest Earned'] 
    ['190208', '000076856', '', '41.00.412005.000.00000000.00.0000', 738.35, '', 738.35, 'Interest Earned'] 
    Traceback (most recent call last): 
    File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None, 
    File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code 
    exec(code, run_globals) 
    File "/mnt/__main__.py", line 189, in <module> 
    main() 
    File "/mnt/__main__.py", line 175, in main 
    with open('\journalentry.csv', 'w') as csvfile: 
    OSError: [Errno 30] Read-only file system: '\\journalentry.csv' 
        # writing to csv file

       with open('\journalentry.csv', 'w') as csvfile: <--- line 175

            # creating a csv dict writer object

            writer = csv.DictWriter(csvfile, fieldnames=fields)



            # writing headers (field names)

            writer.writeheader()

        

            # writing data rows

            writer.writerows(data)        

        

        #return data
    0
  • Jeremy Pond

    Thank you Wade Hays for your recommendation via a different channel to send the data to sheet using the workiva sheets API, then using the get csv data command in the chain to convert the wdesk sheet to a csv file. That is what I needed and I was able to produce the csv output for importing the journal entry to the ERP. 

    0

Accedi per aggiungere un commento.