Excel Script - Refresh data

Copper Contributor

Hi, 

 

I have an excel file which has a data connection. I have been trying to get the data and associated pivot tables to refresh through a script but it doesn't seem to work fully. The script is as follows:

 

function main(workbook: ExcelScript.Workbook) {
  // Refresh all data connections

 

  workbook.refreshAllDataConnections();
  workbook.refreshAllPivotTables
  }
 
I am prompting the script to run through PowerAutomate a couple of times a day. The file will appear to be modified (last modified date of file reflects when the script was last run through PowerAutomate) but the data in the Pivot table is not up to date from the data source.
 
If I open the file online will get a message to enable the queries so I don't know if this needs to be part of the script too?
 
PDTaylor_0-1634887673365.png

 

Any thoughts? 
 
Thanks
4 Replies
Hi, I am having the same issue. Did you find any solution?

@PDTaylor Currently, pivot table refresh/Power Query refresh is not supported with Office Scripts. If you would like to see this feature in the Office Scripts feature-set, please upvote this request here: Enable Office Scripts to refresh Power Query queries · Community (microsoft.com)

Petra, any other suggestions for how with PowerAutomate/OfficeScripts to 'refresh' a query and pivot table ? Want to get to use PowerAutomate to send the latest info including a refresh.

@PDTaylor 

I used your code and it did not work
I did not get an error message but the pivot table just did not refresh
 by adding () at the end and it works

 

sample code

 

function main(workbook: ExcelScript.Workbook) {
  // Refresh Pivot Tables
  workbook.refreshAllPivotTables()
}
 
I know it is a bit late but perhaps someone still has some use for this
;)