#Sitecore Data Exchange Framework Revisited (Reddit to Sitecore Feed)

I did a blog series on DEF and I did a few more follow up blogs. You can find the previous blog on DEF here. After I updated my Reddit Feed example to the latest DEF and doing a presentation on it I decided to do an updated blog.

You can find the my Sitecore Market Place module here. You can find the code in GitHub here.

So, let’s get started.

Overview (what is covered in this blog):

  • What is Data Exchange Framework?
  • How Can it be Used?
  • Sitecore Setup
  • Backend Setup
  • How to Run
  • Scheduling Data Exchange Framework Batch Jobs
  • Final Thoughts

From Sitecore:

Sitecore Data Exchange Framework is designed to facilitate the transfer of data between systems. It allows you to define the logic needed to read data from a source system, transform that data into a format that is compatible with a target system, and write the transformed data into a target system. Developers can build connectors that allow 3rd party systems to serve as source and target systems.

How can it be used?

  • Importing Data from One Source into Sitecore (example rss feed, reddit feed etc…).
  • Exporting Data from Sitecore into Another System (external SQL tables)
  • Reading and Processing xDB contacts.
  • Anything data related. The possibilities are endless.

Sitecore Setup

Below is the overview on how the Data Exchange tenant was setup.

Expanding the Pipeline Batch, you will see the following:

So, let’s start dissecting this stuff.

Sitecore Setup – Value Accessor Sets

  • Used to map field values from the source (Reddit).
  • Used to map source values from Sitecore.

Each Accessor set has a field. I made these fields the same names I was getting from the feed. It made things a little easier to remember.

For the Sitecore field you will use the fields of a template you create. In this case it will be a Reddit item template.

The field value is going to point to the item template of the Reddit feed item. I kept the field naming consistent with the feed.

To bring those together we will use a value mapping set. This will make the connection from the Reddit feed field to the Sitecore field. In this example Title of the Value Accessor Set for the Reddit feed chosen.

In this example created a template that contains settings needed for the field. Template inherits from the endpoint base template. For the Sitecore endpoint I created and used the default values.

The converter type points to a created method in the code behind. The method is used to retrieve the blog path.

Converter Type is defaulted.

Backend Setup – Overview

This is a snapshot of each folder that was created and the corresponding class file.

RedditFeedFieldValueAccessorConverter.cs

The Supported Ids above, the template id ({68BD9AAD-635F-40F3-9ACD-711662C59EEC}) being set refers to the following template. This template inherits from the Value Accessor template installed by the DEF package.

So how this corresponds to Sitecore is simple. A Value Accessor Set item is created and the items underneath it uses this template. In the RedditFeedFieldValueAccessorConverter class it is setup to get the value of that field using the combination of the template and the field name defined in the RedditFeedFieldValueValueAccesorItemModel. You will see how this is tied into other parts of the DEF process as we go along.

In the code you will notice a ValueReader and a ValueWriter are set. The ValueReader is used to read in the feed and match the fields for each Reddit blog item. The field definition is contained in the stringValue. The ValueWriter defines a new PropertyValueWriter class. That class is part of the DEF and used to convert the field values. (This code was changed in 2.1 versus previous versions so you might see this done differently if using an earlier version).

RedditFeedValueReader.cs

This class will process the Reddit Post item and match field name with value. Title, AuthorName, SelfText etc… are field names in the Reddit feed. I believe you can name these differently, but I prefer to keep the same name as it is in the Reddit post item.

RedditEndPoint.cs

The Reddit End Point will have the information for the Blog Path in Reddit. The TemplateId defined points to the RedditEndPoint template. Settings are returned and added to the plugin. The plugin is required to be implemented by the pipeline converter and processor.

This is the model plug in code:

This is values of the Reddit Endpoint. You can see that the Converter Type points to the RedditEndPoint class.

More about this later, but as you can see in the Reddit Pipeline Step the Reddit Endpoint is selected. Now you can see how this all ties together.

Looking in Sitecore you can see where the Converter Type points to the Endpoint Converter and the Processor Type which will get called and receive the end point information and do the Reddit Feed processing.

RedditEndPointConverter.cs

The converter is one of the most crucial parts of the DEF. This is what ties together the pipeline step of the DEF. The SupportedIds value is the template id of the Reddit Pipeline step. As you can see the endpoint settings are passed into the pipeline step.

RedditItemsProcessor.cs

In Sitecore under Pipelines\Reddit Pipeline\Reddit Pipeline Step you will see under Processor Type the RedditItemsProcessor defined.

The next images shows the code for the processor. You will see that the Required EndpointPlugin is defined for RedditSettings.

Endpoint, PipelineStep and PipelineContext should all have values at this point. As you will notice the ILogger parameter is used to set up any custom logging.

If you look at the method RedditFeed, what that does is create a new Reddit class using RedditSharp. It then uses the blogpath setting from the endpoint to retrieve the blog feed.

A collection of reddit feed blogs is then created. It will use fieldnames we defined earlier to match the Reddit feed fields to the fields defined for the new Reddit Sitecore item.

How to Run

Below you will find a Pipeline Batch that was created to run all the necessary steps to process and import the data into Sitecore.

Below are the steps that get run under Pipelines. You can also see above that the Reddit Pipeline is selected.

One of the things I found difficult with DEF now that I have used it quite a bit is getting the correct settings right on each step. I got some help from an expert on Slack. So hopefully this will help someone else.

The first setting Iterable Data Location is important because that is your data that was read in. The Data Location is usually set to Pipeline Context Source.

The Identifier Value Accessor is set to your unique key for your data. Identifier Object Location is usually set to Pipeline Context Source.

Resolved Object Location will usually be set to Pipeline Context Target.

See setting below for mapping. Source and Target are common.

Finally you have the Item Location that will be used to map to the Sitecore Endpoint.

When you first click on the Pipeline Batch you will notice a group of buttons on the ribbon. If something is not correctly setup these buttons will be disabled. To run the Pipeline Batch just click on the Run Pipeline Batch button. While it is running the button will grey out and you will see the Stop Pipeline Batch button enabled. After it is finished running the Run Pipeline Batch will be enabled again.

Results

If you need information on scheduling the DEF process check out my previous blog here.

Final Thoughts

  • The Data Exchange Framework should always be considered when importing/exporting data in Sitecore.
  • It does not completely replace tools such as RAZL as the process would be more manually intensive.
  • The possibilities are endless.

I hope this guide helps those who need to get started with the Data Exchange Framework.

Add Needed JavaScript Code to Any Page in #Sitecore

Many Sitecore sites need different tracking scripts on their website, but for different environments. For instance you might have multiple Azure sites hosting the same site, but in different environments that could be tracked (Dev, QA, Stage, Prod for instance). The proper script should generate for each site instance. This is one way to solve the issue, but I am sure there are other solutions.

In Sitecore I created a Script Settings Folder template. Each folder item contains a Script Setting item. You can have multiple.

I have a configuration filed that contains the settings of the host names for each environment.

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
     <sitecore>
     <settings>
     <setting name="DEV_SERVER_NAME" value="QA.Server.com" />
     <setting name="QA_SERVER_NAME" value="DEV.Server.com" />
     <setting name="PROD_SERVER_NAME" value="Prod1.Server.com,Prod2.Server.com " />
     </settings>
    </configuration>

In the code below in a view (default in this case) the following code is added. The code will compare the current host to what is in the settings and render the appropriate scripts.

string headscripts = "";
string bodyscripts = "";

//Get Parent Item of Script Folder
var scriptdir = Sitecore.Context.Item.Database.GetItem(8DD8956D-7477-41A8-A879-8D3003995F7E);

//Get Hostname from Sitecore to Match the Current Enviroment
string[] hostname = Sitecore.Context.Site.HostName.Split(new char[] { '|' });

//The reason for a string array is because you may have multiple servers like prod that use the same scripts
string[] devservername = Sitecore.Configuration.Settings.GetSetting("DEV_SERVER_NAME").Split(new char[] { ',' });
string[] qaservername = Sitecore.Configuration.Settings.GetSetting("QA_SERVER_NAME").Split(new char[] { ',' });
string[] prodservername = Sitecore.Configuration.Settings.GetSetting("PROD_SERVER_NAME").Split(new char[] { ',' });
string scriptsettingitem = string.Empty;
if(devservername.Intersect(hostname).Any())
{
    scriptsettingitem = "DEV";
} 
else
if (qaservername.Intersect(hostname).Any())
{
    scriptsettingitem = "QA";
}
else
if (uatcdservername.Intersect(hostname).Any())
{
    scriptsettingitem = "PROD";
}
//Synthesis was used in the syntax below, but use whatever works for you. 
if (!string.IsNullOrEmpty(scriptsettingitem))
{
foreach (var childfFolderItem in scriptdir.InnerItem.Children.AsStronglyTypedCollectionOf<IScriptSettingsFolderItem>())
{
   if (childfFolderItem.Name == scriptsettingitem)
   {
    foreach (var scriptitem in childfFolderItem.InnerItem.Children.InnerChildren.AsStronglyTypedCollectionOf<Foundation.Interfaces.Models.I_ScriptSettingBaseItem>())
    {
       headscripts = headscripts + scriptitem.HeadTag;
       bodyscripts = bodyscripts + scriptitem.BodyTag;
     }
break;
   }
}
}

So simple for the most part. What are some other ways to get this done? I would like to learn some other techniques for this.

Milwaukee #Sitecore Meetup Recap. @ParagonDev @layeronemedia #mkesug

This meetup was a big honor for me. I got to present for the first time ever at a public Sitecore meetup. I was nervous going into it for several weeks, but I did my best to prepare. Special thanks go to Joe Ouimet and Derek Dysart for giving me the opportunity to present and putting the meetup together. Also for Paragon Consulting for the awesome food and drinks and Layer One Media for hosting.

I did my presentation on the Sitecore Data Exchange Framework. My goal was to show the demo of my Reddit feed process and get others thinking about how they could use the DEF. I believe I accomplished that and hopefully I wasn’t too confusing. My code and marketplace module are out there so they can be used as a starting point. Also I will probably do an updated DEF blog series for the latest version.

So here we are in tweets and pictures for presentation 1:

Hey my favorite Paragon local sales person from Paragon joined me.

Presentation 2 had me excited. Anything that involves Alexa and Sitecore I am interested in. The topic was “Expanding the reach of your Sitecore Content with Voice-Activated Assistants”. It was presented by Benjamin Adamski and Jeroen de Groot. They did a fantastic job explaining all the benefits and where things are headed.

IMG_8176.jpgIMG_8174.jpgIMG_8178.jpg

Well Milwaukee it has been great. I hope to make the next one.

IMG_8182.jpg

#Sitecore Experience Editor Fixing Datasource Error 404.15 (Too Many Children)

Recently I came across an error that I have not seen before. It seemed this error was only happening on one item. This might be something you never come across or eventually will. Either way there is a good way to prevent it.

The error I saw was below. This happened when you tried to add a datasource to a specific rendering. Not the most descriptive, but it looks like Sitecore returns a big query string of an item’s children.

After examining the rendering I noticed the query that was used in the datasouce location would actually query all children.

The easy fix was to create a components folder and keep the datasource items in there. Then the query could be changed to the following which would only look for that folder. No more errors. Of course, you can expand on the query such as adding the specific templates of the datasource.

query:./child::*[@@templateid='{02A83AA1-F53E-46E5-9BD8-A1601A1E245A}’]

#Sitecore #SCHackathon 2019 Battle of the Team X-Men Developers @ParagonDev

A third year in a row participating in the Sitecore Hackathon with my coworkers at Paragon. I have learned from the previous years I have done this not to make the same mistakes, mostly. See Top 5 Reasons of Failure and Top 5 Reasons the Experience Was Better. However, nothing is ever smooth in the world of web development. So here is a quick summary and lessons learned for next time.

Pre-planning:

We made sure we could get into the GitHub repos. All was good there.

Hours 1-2:

Got the hackathon rules and we started coming up with ideas. I am just going to fix my install for 9.1 that I should have done beforehand that I cannot figure out why it is not working. Well I hopefully can get that finished soon. Okay we came up with some decent ideas and time to start documenting those ideas.

Hours 3-4:

Oh look 9.1 is still not quite installed. My teammates probably want to send me over to Magneto’s team at this point. However at least our idea is solid, but wait a minute…

Hours 5-6:

We need a new idea as all our ideas were already done in different variations. Hey, look at that finally got Sitecore 9.1 working.

Hours 7-12:

Alright we have an idea that solves a problem. Let the coding begin!

Hours 13-17:

Okay finished coding. Let’s surprise our teammate with the new idea we came up with while he was taking a break. He thinks it is a good idea and documentation has begun.

Hours 18-21.5

Video created, documentation created, GitHub repo checked. Let’s finish this up and get it checked in.

Finish:

Time to sleep.

Summary and Lessons Learned

Well I haven’t learned all my lessons. I should have not assumed 9.1 would install as easy as 9.0. In my defense I did have food poisoning the day before and still feeling it. Despite that setback and getting an idea off the ground we made it in time this year. Win or lose I love doing this contest every year. It is a good time to bond with co-workers who I may not normally work and learn new things. One big thing we learned this year was keep the idea simple. That 24 hours comes quick. Solve a problem with your idea, but make sure you can do it in a good time. Documentation takes longer than you think.

Going into the Sitecore Hackathon:

Finishing:

My Second #Sitecore Technology MVP Journey. #SitecoreMVP

I debated if I should write a blog about becoming an Sitecore MVP again, but decided why not. I love blogging so this is a good chance to talk about the last year and my goals for this year. It is a like a diary for my future tech self.

Last year’s goals:

  • Write good quality blogs. (Hey it is an opinion not a fact.)
  • Attend all the local Sitecore meetups and network with local developers. (I made some new friends this way.)
  • Reach out help others in Slack and Sitecore Stack Exchange. (Did my best here, but I don’t always have the right answer.)
  • Create Sitecore Runner Buttons and bring them to the Symposium.
    Using my new MVP status network with the Sitecore family better. (Sorry if I talked too much.)
  • Participate in the Sitecore Hackathon. (Still catching up on sleep.)
  • Make a VLog. (Even bought a new camera last year. This one did not happen. :()
  • Update my DEF Redditt Module in the Sitecore Marketplace. (I have this almost ready just need the time.)

This year’s goals:

  • Write some more good quality blogs. (Does this one count? ;))
  • Attend all the local Sitecore meetups including one in Milwaukee. (Make sure you order enough food for me.)
  • Reach out help others in Slack and Sitecore Stack Exchange. (I love helping others so I won’t stop trying.)
  • Create Sitecore Runner Buttons and bring them to the Symposium. (If you did not get this highly sought after collectible I will be bringing them again.)
  • Using my new MVP status network with the Sitecore family better. (I am not hiding. Well behind this keyboard I am.)
  • Participate in the Sitecore Hackathon again. (Maybe I should sleep before it starts.)
    Make a VLog. (I have to make this happen.)
  • Finish that update on my DEF Redditt Module in the Sitecore Marketplace. (I am going to release it before the end of the year.)

If you are an MVP hopeful and you are reading this now I want to leave you with some advice the guy that was supposed to at the Sitecore Symposium said in a movie once. I put this quote right up there with Rocky quotes.

Image result for will smith pursuit of happiness quote

Adding Custom Dropdown Button in #Sitecore 9 to Content Editor Ribbon

I published a blog recently for creating a dropdown in the Rich Text Editor (RTE). You can find that here. I needed to do something similar for the content editor, so the same functionality could be done in text fields by saving the value in the clipboard.

In this case I will be adding a Token button to the Ribbon in the content editor. This button will contain a drop down.

In the Core database in the content editor you can add a button using the following path. I added the Tokens directory which is a Chunk item.

/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Tokens/

Underneath the chunk I created a Large Gallery Button item. This type of item contains a drop down as seen above.


In my Visual Studio project, I added two files. The structure is below. This structure should match the structure in your site.

Gallery Tokens.xml contains the following code. The highlighted area is important as that tells Sitecore where to find the CSS code for the button and the code behind.

In the CodeBeside in the xml code it points the following extension. This extension will get the list of items in Sitecore and build a drop down list.

  1. public class CopyTokenMenu: GalleryForm {  
  2.     protected Menu Options = new Menu();  
  3.     static readonly Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase(“master”);  
  4.     readonly Item _parentTokenFolder = master.GetItem(“/sitecore/content/CustomerPortal/Site Settings/Tokens”);  
  5.     public override void HandleMessage(Message message) {  
  6.         Assert.ArgumentNotNull((object) message, nameof(message));  
  7.         if (message.Name != “item:load”) {  
  8.             base.HandleMessage(message);  
  9.         } else {  
  10.             Invoke(message, true);  
  11.         }  
  12.     }  
  13.     protected override void OnLoad(EventArgs e) {  
  14.         if (_parentTokenFolder == null || !_parentTokenFolder.HasChildren) {  
  15.             return;  
  16.         }  
  17.         Assert.ArgumentNotNull((object) e, nameof(e));  
  18.         base.OnLoad(e);  
  19.         if (Context.ClientPage.IsEvent) {  
  20.             return;  
  21.         }  
  22.         Options.Controls.Add(new LiteralControl(

    Copy token to place within your text:

    ));  

  23.         foreach(Item token in _parentTokenFolder.Children) {  
  24.             Options.Controls.Add(new LiteralControl(“<p><button class=button title=’copy’ id=\”” + token.Fields[“TokenValue”].Value + “\” onclick=copytext(‘” + token.Fields[“TokenValue”].Value + “‘)><img src=\”/temp/iconcache/office/16×16/documents_empty.png\”></button>&nbsp;” + token.Fields[“TokenValue”].Value + ” – “ + token.Fields[“Description”].Value + “</p>”));  
  25.         }  
  26.     }  
  27.     private static Item GetCurrentItem() {  
  28.         string queryString1 = WebUtil.GetQueryString(“db”);  
  29.         string queryString2 = WebUtil.GetQueryString(“id”);  
  30.         var index1 = Language.Parse(WebUtil.GetQueryString(“la”));  
  31.         var index2 = Sitecore.Data.Version.Parse(WebUtil.GetQueryString(“vs”));  
  32.         Database database = Factory.GetDatabase(queryString1);  
  33.         Assert.IsNotNull((object) database, queryString1);  
  34.         return database.Items[queryString2, index1, index2];  
  35.     }  
  36. }  

    This is the token item created that will be read in for the button drop down.


    This is the style sheet code that is referred to in the xml file.


    In the Home Ribbon in the Content Editor the Token button now appears. Clicking it will bring down a drop-down list. Clicking on the icon will copy the value to the clipboard.

    That is, it. I hope this helps some of you. I enjoyed doing this and wanted to make sure it was documented as it could be difficult at first to figure out all the pieces.

Second Annual Chicago Meets Milwaukee #Sitecore Meetup Recap. @ParagonDev @GeekHive @_Americaneagle @jouimet @DDysart #SitecoreSym

After attending the first combined Sitecore meetup last year I was hoping the combined meetup would happen again. Well my hopes were answered. Joe from Geekhive invited me to speak on the Sitecore Symposium panel. I couldn’t wait to share my experience.

When I got there the usual food and goodies were there. The pizza was very good even though it was from Wisconsin.

The first presentation was on Coveo Hive. I am always impressed with Coveo and they continue to improve their product making them a vital search framework in the Sitecore world.

Looks like Hive introduces many new and exciting things.

Next was the Sitecore Symposium Panel. Joe from Geekhive did a great job hosting. It was great reliving the Symposium experience and sharing with others what we learned.

This meetup reminded me of one my favorite crossovers. I can’t wait for the next one.

#Sitecore October 2018 Chicago Meetup Impressions

This was the second Sitecore meetup this year. This one was at a different location. It was at Productive Edge in downtown Chicago. It was a scenic walk from the train. The office itself was setup nice. A lot of the attendees will be at the Sitecore Symposium, so it was nice to connect with them. We also used the Symposium app scan on the network menu to connect with each other. Of course, they had my favorite pizza, Lou Malnati’s.

The first presentation was a joint effort by Ryan Kuchler and Will Rolloff. This covered Context Marketing from both a marketer’s point of view and developers’ point of view. One of the things I believe that are overlooked by clients after a Sitecore site is complete is the powerful marketing tools that are in Sitecore.

Summary of topics:

  • Marketers – Get to know Context Marketing and deliver personalization to your audiences with out of the box Sitecore features and configurations – Today!
  • Developers – Architect and deploy the right application components that enable the business to drive context marketing and scaling it to meet your organizations needs using Microsoft Azure

They did an excellent job presenting and it was the best presentation I have seen on Context Marketing. I walked away with much more specific understanding on how all the different pieces worked. I especially liked the parts were previous versions of a page were compared to a new page, setting the score for each campaign and swapping out presentations based on visits. I will be using this information in the future.

Last, but not least Will presented tips for first time Symposium attendees. I wish I had these for my first Symposium. Even so it being my second Symposium coming up I still learned a few things.

One thing he forgot to mention. Take all the Sitecore bling you can with you.

Sitecore Symposium for Newbies #SitecoreSYM @ParagonDev

So last year being my first Symposium I did not know what to expect. I know there will be a lot of new attendees this year, so I wanted to give you some advice to make it the best experience that it can be.

Network, Network, Network

Starting at the airport I must have made at least five contacts with people also travelling to the Symposium. Waiting for my plane and the bus to the hotel. Also, I met in person a few people I have talked to online. I even ran with one of them. Yes, running with someone is a good way to network. As you make connections always make sure you have a bunch of business cards with you, so they contact you for whatever reason. A lot of the people you will meet may be someone you work on a project with in the future or may need to reach out to for some help.

Get to Know Your Co-Workers.

A lot of us work remote and don’t interact with our co-workers daily. If we do it is usually via email, skype, slack, WebEx etc.… Being at the Symposium face to face with people you work with can help establish a better working relationship. The old saying a face with the name is never more so true in today’s world. I also ran with one of my co-workers.

Get some nice bling.

From the time you arrive at the Symposium to the time you leave there are so many things with different Sitecore branding that you can take with you. I collected several buttons, flashlights, a hotel key, small plastic beer mugs, glasses, ice cubes you name it with Sitecore logos on it. Not to mention I got a lot of cool stuff from all the vendors there. Including stuff like pop sockets and socks.

Give some nice bling.

I mentioned buttons above and this year I decided to do my own to trade and give out. I think this will not only be a good way to promote my blog site, but break the ice with several other attendees. The company I work for Paragon was giving out cool flashlights last year. I made sure to hand those out whenever I could.

Be comfortable and dress nice.

Working remote I honestly don’t dress business casual these days. The recommended dress for the Symposium is business casual. I normally wear running shoes, but I thought I would get something that was like a classic sneaker, but could also work with business casual attire. Well good-looking shoes does not equate to comfortable. I was in so much pain it got harder to walk around every day (you will do a lot of walking). I learned my lesson and this year I plan on wearing shoes that are broken in and comfortable. You can look up business casual attire since it is interpretation is open, but considering you will be representing your employer there you want to dress nice. I am fortunate enough to have shirts with Paragon’s logo on it.

See you all there!

092018_0302_sitecoresym5