Do import jobs to Sitecore in 5 minutes

I want to show you just how easily an import can be done to Sitecore from any system, that can give you the data in xml, csv, sql, or other formats.

This blogpost uses the Sitecore DataSync module to do the ground work. This can be downloaded from marketplace.sitecore.net for free.

Step 1: Create a new Xml Data Map Open Sitecore and locate the system/Modules/DataSync folder and create Your XmlDataMap:

 

 

Step 2: Create the folder you want Your imported items to go:

 

 

Step 3: Add the datasource, location and Language for Your import

Go to the XmlDataMap item and add Your webservice URL, in Our case we use an event list like the following URL (you can just as well add a file path to a xml-document or add the Xml to the Data Field):  

Set the item you just created in "Import To Where" and select the Language you want your items created in. You also need to decide which Field in the import data you want to use for the Item Name. IE we use the event name:

Step 4: Examine Your import Source and Select what to import

Here is my import xml. What I want to be the basis for each item created, is the /EventResult/Events/ListEvent elements:  

 

Therefor I add that xPath query to the Query Field:  

Step 5: Set which template Your imported items should be created as

The import will create items based on this template. I Select a template that is an Event:  

Step 6: Add the Fields

Now you are ready to map the imported data to Your Fields. Go to the Fields folder below the DataMap item and create a ToText Field item. In this example we want to map the Name and the BookingUrl:  

Enter the "To What Field", which is the Sitecore fieldname. Add the "From What Fields", which is the name of the import field:  

Do the same with BookingUrl, and other fields you want to map.

Step 7: Run the import You do that by clicking the XmlDataMap, and Select "DataSync" in the menu and "Run Sync Job". After running the wizard you should get a result like this:  

The imported items is now imported:  

Congratulations you have just done a import from a webservice to Sitecore in 5 minutes!

What if you want to run this import more than once?

Then the same items will be created again and again. Can I avoid this? Yes, you can and it's pretty easy.

Step 1: Add a key that uniqly identifies your item

To be able to synchronize Your items, you need to import a Field that can be the key. This can be any Field that uniqly identifies the item. In our case the CbisProductId is unique.  

 

Step 2: Set the synchronization settings

On the XmlDataMap item, we check the "Sync Folder By Updating Already Existing Items and Selects Our newly created key Field:

Step 3: Run the synchronization

We run the import again and notices that now nothing is updated. This means that no items was actually created this time, since they were already there.

 

If you look in the import folder the 20 items from before is still there. We have now imported and synchronized data from a webservice into Sitecore.

This is ofcause the most basic example of doing an import. For more look at the documentation at marketplace.sitecore.net. If you want to save time to do more for your customers - the DataSync module will help you with just that.