When trying to update SharePoint Document Libraries or SharePoint lists on a regular basis it is useful to be able to set specific metadata.
One type of metadata that you might be interested in setting is Content Types. Content types allow you to set templates, retention policies and define a group of columns for that type.
The following page will show you how you can set the Content Types on SharePoint list items and Document Library items using Data Synchronisation Studio.
Before getting started you need to ensure you have the following:
If you do not have Data Synchronisation Studio you can get a free evaluation edition.
If you do not know the ID value that SharePoint is expecting we recommend setting content types for a couple of items manually and then preview the results returned from SharePoint in Data Sync. You can then make a note of each ID and update your source data accordingly.
Some common ID types are:
You have a couple of options when updating the source data:
The manual process is self explanatory, but you can find descriptions on how you might configure the other options below.
You need to start by configuring your Data Sync project so that you are connected to your source data and the target is connected to your SharePoint list you want to update. Then you can choose between creating a calculated column or creating a lookup.
You can use calculated columns and a CASE function to return the relevant ID when the content type name in the source data matches the case in the function.
The expression below returns the ID for message, item, issue, and task and if the source column contains something that doesn't exist in the expression it will return a default value of the issue ID.
CASE(ContentTypeName, "0x0100860DBE824AC9614589A21DCD29DB5448007A823F8834051D4F986EA19A5812FF09", KV("Message", "0x010700B796C8AF0D82994A86E8DAF1B01A3FFB"), KV("Item", "0x0100860DBE824AC9614589A21DCD29DB5448007A823F8834051D4F986EA19A5812FF09"), KV("Task", "0x0108004931F959CF5D224F8A156604BB7B6005"), KV("Issue", "0x01030066DC9B12B8DE924CBD18288FA706EA1C"))
The syntax for this is:
CASE(ColumnName, DefaultValue, KV(Value, ValueReturned), KV(Value2, ValueReturned2), KV(Value3, ValueReturned3))
Clicking OK will create the column in your source window and you can then add this column to the schema map and map this to the Content Type ID column in SharePoint
If you have a list of content types you want to use within your list or library then you could store these and their corresponding ID's in another list or datasource and perform a lookup on each type.
Please be aware that if there is a type that does not exist in the list you create and therefore has no ID being returned SharePoint will default the type to Item.
Here I have created a SharePoint list to hold the content type names and their corresponding IDs and I will lookup the type name I have listed in my source data against this list to return the relevant ID. This list has been named ContentTypes.
To create the lookup just drag and drop the ContentType list onto the column in the source data that contains the name of the content type, in this example it is ContentTypeName.
This will then open the lookup configuration window where you can define that it is the content type that is being looked up. This should look similar to the below:
Click OK to create the lookup and now you can access all of the columns within the ContentTypes list. I'm adding the Content Type ID to the schema map by expanding the lookup columns and checking the checkbox.
You can then map this column to the Content Type ID in your SharePoint list, and add any additional columns you need. Please make sure to select a key column that can be used to identify each record, in this case it is Title.
To show you that the lookup is working I have added in the column from the source that returns the content type name and previewed the data to show the different IDs that are returned.
Make sure you remove the Content Type Name column before synchronising as this will throw an "Invalid Request Error" if you try to synchronise to it.
We can then preview the changes to be made to add these to SharePoint by clicking Compare A > B.
This will show us any add, update or delete actions that need to be performed to make the SharePoint list match the source data.
Please note that deletes are disabled by default but will still show in the results if the record does not exist in the source data set.
To enable deletes please set EnableDelete to True in the target connection properties.
There are 6 records to add and we can now synchronise the results by clicking Synchronise and then Start.
The records will then be added and updated in SharePoint with the corresponding content type.
For other ideas on how you can integrate with SharePoint take a look at our SharePoint Solutions page.