Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This example shows how to run a script on an Azure SQL instance and send an output summary by email.
Prerequisites
To get started, you must complete the following prerequisites:
- A tenant account with an active subscription. Create an account for free.
- A workspace is created.
Create a script activity and configure its output to be sent by email
In this example, you create a Script activity to execute a script on an Azure SQL instance, and then send an output summary by email.
Create the Script activity
Create a new pipeline in your workspace.
Search for Script activity in the pipeline Activities pane, and select it to add it to the pipeline canvas.
Note
Depending on the size of your browser window, the word Script may be hidden, showing only the icon.
Select the new Script activity on the canvas if it isn't already selected.
Refer to the General settings guidance to configure the General settings tab.
Create the connection and specify a SQL script
Select the Settings tab, and then select an existing Azure SQL or Azure SQL Managed Instance connection from the Connection dropdown, or create a new connection, and specify its configuration details.
Specify a script. You can execute any query, or non-query scripts that perform operations on the database as well, in the Script textbox on the Script activity settings page. For this example, you can use this simple SQL script:
SELECT 'This is an example of output generated by a SQL script.' as OutputText
Create an Office 365 Outlook activity
Search for the Office 365 Outlook activity on the Activities toolbar. The text description may not be displayed if the window size isn't large enough, so you can look for the icon or expand the window if necessary.
Link the activities
Select the Script activity, and then drag it's On success output (a green checkmark on the right side of the activity in the editor pane) to the Office 365 Outlook activity.
Configure the Office 365 Outlook activity
Select the Office 365 Outlook activity in the pipeline editor, and then select its Settings tab, and Sign in to your Office 365 Outlook account that will send the email.
After you sign in, you see the outgoing email template. Provide a list of emails for the email to go to in the To text box, and a Subject in that text box. Note that all fields in the template support dynamic content. Select the Body text area and then select Add dynamic content, to customize what we will add. Select Activity outputs if it isn't already selected, and then select the output of the activity. Select OK to use this dynamic content as the Body of the email. You can use any combination of outputs to generate emails of any level of complexity you need. In this case we use the following expression to output the returned value from the SQL script:
@concat('Output from script activity: ', activity('Script1').output.resultSets[0].rows[0].OutputText)
You can also specify advanced settings for the email if you wish, including an alternate From (Send as) value, CC, BCC, Sensitivity, Reply To, or Importance fields:
Save and run or schedule the pipeline
Switch to the Home tab at the top of the pipeline editor, and select the save button to save your pipeline. Select Run to run it directly, or Schedule to schedule it. You can also view the run history here or configure other settings.
Confirm success
After the pipeline runs successfully, check the account(s) you specified in the To box of the Office 365 Outlook activity settings to validate the output.