Edit

Share via


Run a Script activity and send an output summary by email

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:

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

  1. Create a new pipeline in your workspace.

  2. Search for Script activity in the pipeline Activities pane, and select it to add it to the pipeline canvas.

    Screenshot of the Fabric UI with the Activities pane and Script activity highlighted.

    Note

    Depending on the size of your browser window, the word Script may be hidden, showing only the icon.

  3. Select the new Script activity on the canvas if it isn't already selected.

    Screenshot showing the General settings tab of the Lookup activity.

Refer to the General settings guidance to configure the General settings tab.

Create the connection and specify a SQL script

  1. 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.

  2. 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
    

    Screenshot showing the Script activity settings page with the Script textbox highlighted, and the query specified inserted as its value.

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.

Screenshot showing the Office 365 Outlook activity button on the Activities toolbar.

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.

Screenshot showing the On success output of the Script activity with its arrow dragged onto the Office 365 Outlook activity.

Configure the Office 365 Outlook activity

  1. 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.

    Screenshot showing the Office 365 Outlook activity Settings tab with the Sign in to Outlook prompt.

  2. 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)

    Screenshot showing the Pipeline expression builder with the output of the Script activity selected for its dynamic text from the Activity outputs tab.

  3. 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:

    Screenshot showing the advanced settings for the Office 365 Outlook activity.

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.

Screenshot showing the Home tab in the pipeline editor with the tab name, Save, Run, and Schedule buttons highlighted.

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.

Screenshot showing successful execution of the pipeline.