How can a script in an analysis be triggered automatically when the analysis is automated to send an email?

I have written a script to change the column names of a graphical table dynamically when ever the source table is updated with latest data. But the script is been triggered by a button added in a text area. I need to automate this analysis and sent this by e-mail. I have created the automation job to Open the Analysis and Send e-mail but I need help in running the script in the analysis without any manual triggering.

(2) Answers