data/authors/Paul Logan.json

Populating Sharepoint List with On-prem SQL Server data

Contents

The Quality Department had created a form on the company’s Sharepoint to record quality issues received from various channels - customers, sales reps, customer services etc.

This form required a customer lookup to assign the quality issue to.

The customer data resided within an on-premise SQL Server database.

A Sharepoint List was needed that could be used as the source list for the custoemr field on the form.

The List needed to be initialised with the existing active list of customers from the database.

Subsequent updates would be necessary to update the customer list with new customers that were added to the on-premise database.

These updates should be automated according to a schedule or an event.

  • Sharepoint - Microsoft’s collaboration and document management platform.

  • On-Premises Data Gateway - to enable data transfer between on-premises data and several Microsoft cloud services, including Power Automate.

  • Power Automate - Microsoft’s workflow and business process automation platform.

  • Licencing - The SQL Server Connector is required to connect to a SQL Server database. This is a premium level connector and therefore requires a Power Automate Premium licence. From Microsoft’s own pricing documentation, other licencing scenarios are an option (Copilot Studio, certain Dynamics 365 licences).

Microsoft’s Reference documentation.

Microsoft’s Architecture documentation.

This requires .Net Framework 4.8 to be installed on the server the gateway will be installed on - a server restart will be required.

Before you can populate the list, you will need to create it.

Within the site on Sharepoint that you will be using the List, click:

New => List => Blank List => Name it => Create.

As the list I am creating is for a lookup list, I will be requiring two pieces of data from the Customers table => account code and name. Just like an HTML select element, these will represent the value and display text respectively.

So I click the dropdown link in the column header called Title, Column Settings => Rename to rename it AccCode. I then click “+ Add Column” in the next column and name it Name.

The Title column

The Title column is a “special” column in Sharepoint lists.

Using it the way I have described above is totally acceptable, but it can only be done for text type values.

See some discussion aboit it here.

Harking back to Power Automate’s original name, Flow, we create a new scheduled cloud flow.

Step 1 of flow
Step 1 of Flow

For draft 1 of this flow, here are all of the actions, formatted as:

Connector Name - Action Name - My custom name for the action (where applicable):

  1. Schedule - Recurrence
  2. Sharepoint - Get Items - Get existing customers from list
  3. Control - Apply to Each - For Each Customer
  4. Sharepoint - Delete Item - Delete Customer From List
  5. SQL Server - ExecuteProcedure_V2 - Execute Get Customers Stored Procedure
  6. Data Operations - Parse JSON
  7. Control - Apply to Each - For each Customer From Database *
  8. Sharepoint - Create Item - Create Customer In List
The complete Flow
The complete Flow

*A gotcha to watch out for in the second Apply to Each action (renamed as “For each Customer From Database”), is the need to modify the action’s default previous step output when you select the Body Table 1 output from the Parse Json action.

The buggy default Apply to Each action
The buggy default Apply to Each previous step output

As it is, the output will generate a null value for the action:

You will need to manually paste in the altered reference to the table within the JSON body:

The updated Apply to Each previous step output
The updated Apply to Each previous step output

Save and Test the flow.

Browse to your List in the Sharepoint site you created it in and you should see the data from your on-prem database listed.

This List is now available as a new field in forms that are created in Sharepoint:

List available as field in form
List available as field in form

Not long after you release this List to your “power” users, you will get an email (or a walk-in) to tell you that the list is showing duplicate items.

This is due to the default configuration/limitation of the Get items action that means it will only retrieve 100 items.

Not all items are retrieved initially
Not all items are retrieved initially

The solution to the issue, detailed here, is to up the limit to a value greater than the number of items in the list (with a current maximum of 5,000 items).

Setting the number of items to retrieve to the max.
Setting the number of items to retrieve to the max.