Keep your Sharepoint in sync. Download and try today.
SharePoint Integration: How to keep existing SQL foreign key relationships and map to SharePoint lookups
You can easily integrate almost any external data source with native SharePoint lists using the Layer2 Business Data List Connector, especially SQL tables or queries. But how to map existing SQL foreign key table relationships to SharePoint lookups? See below for a simple workflow-based approach.
No problem to sync SQL tables or queries with native SharePoint lists using the Layer2 Business Data List Connector. But how to map existing foreign key relationships between these tables to SharePoint lookups? Generally you can solve these issue using a workflow approach as shown in the sample below.
Fig.: Sample database schema with two tables that are in a foreign key relationship.
The table ‘Cars’ contains a column with the name ‘ColorCode’. The column contains a reference (foreign key relationship) to the column ColorID in the table ‘Colors’. You have to create both lists (cars and colors) in your SharePoint and connect the lists via the BDLC with the tables as usual. See product description for more details.
Fig.: SharePoint lists connected to the database tables via BDLC
In the list ‘cars’ you have to create an additional lookup column manually, for example with name ‘Color Value Lookup’. This is a lookup field to the list ‘Car Colors’ to the field ‘Color’. If you start the update mechanism for both lists, you can see that the lookup column isn’t filled with values automatically. To create this association in SharePoint, you have to create a workflow for this list, which starts if an item is created or updated.
Fig.: SharePoint Designer Workflow
First of all create an action ‘Set Field in Current item’. After this step you can specify the field and value to set. Select the manually created Lookup field. In this case ‚Color Value Lookup‘.
Fig.: Select Values to set in the SharePoint Designer workflow.
In the next step you have to select the value which the field should be filled with.
Fig.: Select Values to set in the SharePoint Designer workflow.
Select the data source list (‚Car Colors‘) and the field ‚ID‘ of this list.
Fig.: Select Values to set in the SharePoint Designer workflow.
Fig.: Select Values to set in the SharePoint Designer workflow.
In the next step you can specify the ‘primary key information’ (ColorCode) in list ‘Car Colors’ and the associated field ‘ColorCode’ in the current list. If you save your settings, there is a popup message with a warning, that your selection isn´t a field with unique values. You can ignore this and save the settings with ‚Yes‘.
Fig.: Save your workflow settings.
Now you are done with the workflow creation. To publish it, press the button ‘Publish’ in the ribbon.
Fig.: Publish your workflow.
As a next step you can update the SharePoint list ‘Cars’ using the BDLC ribbon button.
Fig.: Update list items with external data via BDLC manually.
If you currently have items in the list, you have to delete all of them and update again. Thats because of the BDLC changes only modified items. The lookup field is now filled with the information from the list ‘Car Colors’.
Fig.: The lookup field is now automatically maintained by the workflow in case of any data changes.
If the workflow didn’t work as expected, you have to resave the BDLC settings by clicking ‘OK’ in the BDLC settings page and update your list again. Please note that this can be used as a replacement for the Layer2 Key Value Lookup Column product that will be not available for SharePoint 2013.
Summary
Existing foreign key relationships between normalized SQL tables were mapped to SharePoint lookup-type relationships using the Layer2 BDLC to connect to the external data and simple SharePoint Designer workflows to keep the lookups current in case of external data changes.
READY TO GO NEXT STEPS?