1

I am using Google Sheets api for creating a spreadsheet with multiple sheets, all of which have custom function, which is written in Google App Script. This function fetches data from my server, and usually there are at least 25 function calls.

Now I want to download the file using google sheets api, once all the custom functions are finished properly.

How do I wait for all custom functions to finish and then proceed with my google sheets api calls?

Lakhan
  • 73
  • 1
  • 8

1 Answers1

0

If anyone else is still looking for an answer, I found a way that may not be ideal, but it works.

def check_if_ready(spreadsheet_id):
    no_of_retry = 5
    response = service.spreadsheets().get(spreadsheetId=spreadsheet_id,fields='sheets(data.rowData.values(effectiveValue))').execute()
    i = 1
    while 'errorValue' in str(response):
        if i > no_of_retry:
            return Response({'message': 'Error!'}, status=status.HTTP_404_NOT_FOUND)
        response = service.spreadsheets().get(spreadsheetId=spreadsheet_id,fields='sheets(data.rowData.values(effectiveValue))').execute()
        time.sleep(5)
        i += 1

since errorValue will be returned for the custom function which is not calculated properly or is still being calculated at the time of the API call.

Lakhan
  • 73
  • 1
  • 8