Getting Started Quickly with #Sitecore CDP (Customer Data Platform)

Sitecore CDP formerly Boxever is something you are probably hearing a lot about these days. As a developer you can implement it easily and as a marketer you can take advantage of some of the features as soon as it is implemented. Here are the steps in order I did to get started.

1. Get a sandbox account.

Should be able to get a login for the CDB Sandbox from your Sitecore rep. You can find the sandbox site here. This is a shared sandbox so you will need to be careful not to change anything that someone else has setup. It is ok to look and see what others have setup. That is one advantage of a shared sandbox.

When you first login to your sandbox account you should see a message like this:

2. Get your keys and Create Point of Sale Value.

To get your keys go to the gear icon at the bottom left and select System Settings then API Access.

Copy both keys. Please note in my example I did not use the API Token.

3. Create Point of Sale

Selected System Setting then Point of Sale. Click on the create button and fill out the required fields. In my case since I am using the Lighthouse Demo I called my POS LighthousePOS. Well I can’t remember if I created or it was already out there.

4. Implement code. (SXA Example)

The next step is to implement the script needed to integrate CDP with your site. The script should look like the following. As of this blog the target version should be 1.2 and s.src should be 1.4.8. You will need to add your client key.

// Define the Boxever queue
   var _boxeverq = _boxeverq || [];
   // Define the Boxever settings
   var _boxever_settings = {
       client_key: 'client key goes here', // Replace with your client key
       target: 'https://api.boxever.com/v1.2', // Replace with your API target endpoint specific to your data center region
       cookie_domain: '.lighthouse.localhost', // Replace with the top level cookie domain of the website that is being integrated e.g ".example.com" and not "www.example.com"
       pointOfSale: "LighthousePOS",
       web_flow_target: "https://d35vb5cccm4xzp.cloudfront.net"
};
   // Import the Boxever library asynchronously
   (function() {
        var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true;
        s.src = 'https://d1mj578wat5n4o.cloudfront.net/boxever-1.4.8.min.js';
        var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
    })();

I kept this pretty simple and for now created a script and put it under the Base Themes\Main Theme\Scripts folder. I created a script item called cdp-script.

5. Create an Experiment

From the menu expand Experiments and choose Web. Click on the Create Experiment button.

From there you want to click on the add variant button.

After you click on Add Variant there will be a side menu that will appear. Choose My Library Templates.

We will choose a simple popup takeover.

Change anything you want to. In this case I changed the background and font colors. You can also change HTML and script

Once done, make sure you click on the Save button then Close when you see the checkmark.

You will see the new Popup in a list. Click on the Preview button, enter in your site with the CDP script and click the go button. If everything worked correctly you should see the popup.

Once the site opens, in this case my local demo site you will see the popup created.

Another option to try is Experiences the setup is similar to Experiments. You can find on the same menu as Experiments.

This should get you started. I would take a look at what others have done since it is a public sandbox. There are a lot of possibilities with CDP and we are only scratching the surface. For more information on getting started please take a look at this video that was released as I was putting together this blog.

#Sitecore #Docker Containers Syncing Database Changes the Lazy Way

I have been using Docker/Containers for about six months. I have to tell you I really like using them. A recent project I am helping architect the solution for I decided to have the other developers use them. There were some hiccups along the way getting some developers setup, but so far it has worked out well. I think I convinced them change is good.

Ted Lasso Memes At Your Service!

Anyway one of the things I have learned is how easy it is to deploy things to containers. One of them being databases. Normally you would install Sitecore and serialize items or use Sitecore packages for changes. We are doing that. However we had multiple sites/tenants to create in SXA and wanted to make sure the team was in sync from the start. With the out of the box Sitecore tools for Docker it is easy to do.

If you look into your docker\data\mssql folder (could be a different folder depending how you setup your volume, but in this case I am using the default) you will find the ldf and mdf files for each Sitecore database. Just copy the ones for the database you want to share and put it in a shared folder for other developers. I actually stored them in Teams.

The developer who is installing the database should do a docker-compose down first. Then copy the database files to their local data\mssql folder. Once they are a copied to the other developer’s local data\mssql folder they will need to do a docker-compose up. Now they will have the same database changes as the other developer for their containerized Sitecore instance. BTW inside the mssql image you can view the database files.

So what happened? Was it magic? Well if you think PowerShell is magic then it was. As with custom web changes databases are also deployed into the images using the built in Sitecore tools. So as soon as the files are copied the watcher does its thing.

So one catch with this that I noticed recently. If you clean out your Docker Data\Deploy folders by running something like the clean.ps1 script it clears out the data\mssql folder. Which means the database changes could be lost. I will look for a workaround for this, but one thing that I did was create a clean script that keeps the database folder contents. See below for an example:

# Clean data folders
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\data") -Directory | ForEach-Object {
    $dataPath = $_.FullName

    Get-ChildItem -Path $dataPath -Exclude ".gitkeep", "license.xml", "*.ldf", "*.mdf" -Recurse | Remove-Item -Force -Recurse -Verbose
}

# Clean deploy folders
Get-ChildItem -Path (Join-Path $PSScriptRoot "\docker\deploy") -Directory | ForEach-Object {
    $deployPath = $_.FullName

    Get-ChildItem -Path $deployPath -Exclude ".gitkeep", "license.xml", "*.ldf", "*.mdf" -Recurse | Remove-Item -Force -Recurse -Verbose
}

I will update this blog post I am sure as things evolve with Docker/Containers, but I hope for now this will give one way to share database changes. If you have a better way I would love to know.

Basic Authentication with #Sitecore 9.3

A few months back I was given a task to put in basic authentication into Sitecore 9.3. It was mainly from preventing anyone to get into staging sites. I came across and older blog that is currently missing. I wanted to give them credit since it was the inspiration for this blog. You can find the original blog post on the web archives here. I have made some of my own updates including Rules Based Configuration.

using System;
using System.Web;
using Sitecore.Diagnostics;
using Sitecore.Pipelines.HttpRequest;
using System.Text;
using System.Net.Http.Headers;
using System.Linq;

namespace Abc.SharedSource.SitecoreProcessors
{
    public class BasicAuthentication : HttpRequestProcessor
    {
        private bool CheckPassword(string username, string password)
        {
            string[] userlist = Sitecore.Configuration.Settings.GetSetting("BasicAuthUsername").Split(',');
            string[] passwords = Sitecore.Configuration.Settings.GetSetting("BasicAuthPassword").Split(',');

            if(userlist.Contains(username) && passwords.Contains(password))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private void AuthenticateUser(string credentials)
        {
            try
            {
                var encoding = Encoding.GetEncoding("iso-8859-1");
                credentials = encoding.GetString(Convert.FromBase64String(credentials));

                int separator = credentials.IndexOf(':');
                string name = credentials.Substring(0, separator);
                string password = credentials.Substring(separator + 1);
             
                if (!CheckPassword(name, password))
                {
                    HttpContext.Current.Response.StatusCode = 401;
                }
            }
            catch
            {
                HttpContext.Current.Response.StatusCode = 401;
            }
        }
        //Basic Auth Code End

        public override void Process(HttpRequestArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (Sitecore.Context.Item != null || Sitecore.Context.Database == null || args.Url.ItemPath.Length == 0)
                return;

            if (Sitecore.Configuration.Settings.GetSetting("TurnonBasicAuth") != "True" || Sitecore.Configuration.Settings.GetSetting("TurnonBasicAuth") == "") return;
            if (PatternMatch()) return;
            var request = args.HttpContext.Request;

            var authHeader = request.Headers["Authorization"];
            if (authHeader != null)
            {
                var authHeaderVal = AuthenticationHeaderValue.Parse(authHeader);

                // RFC 2617 sec 1.2, "scheme" name is case-insensitive
                if (authHeaderVal.Scheme.Equals("basic",
                        StringComparison.OrdinalIgnoreCase) &&
                    authHeaderVal.Parameter != null)
                {
                    AuthenticateUser(authHeaderVal.Parameter);
                }
            }
            else
            {
                args.HttpContext.Response.StatusCode = 401;
            }

            if (HttpContext.Current.Response.StatusCode == 401)
            {
                string Realm = Sitecore.Context.Site.TargetHostName;//HttpContext.Current.Request.Url.AbsoluteUri;
                args.HttpContext.Response.Clear();
                args.HttpContext.Response.Headers.Add("WWW-Authenticate",
                    string.Format("Basic realm=\"{0}\"", Realm));
                args.HttpContext.Response.Flush();
                args.HttpContext.Response.End();
            }
        }
        bool PatternMatch()
        {         
            string[] mockUrls = Sitecore.Configuration.Settings.GetSetting("ExcludedPaths").Split(',');
            string url = Sitecore.Context.Site.TargetHostName;// HttpContext.Current.Request.Url.AbsoluteUri;
            foreach (var urlval in mockUrls)
            {
                var containsurl = url.Contains(urlval);
                if(containsurl)
                {
                    return true;
                }
            }
            return false;
        }
    }
}

Since this is Sitecore 9.3 the configuration below is using rules based. ūüôā More than likely you would want to require the ContentManagement role, but you can modify the configuration to use any roles and environments. I put the username and settings in the configuration since Sitecore will also have its own and in this case is only for preventing anyone who accidently finds the site from seeing anything.

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:localenv="http://www.sitecore.net/xmlconfig/localenv/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore role:require="ContentManagement, Standalone">
    <pipelines localenv:require="DevBuild or LocalDeveloper">
      <httpRequestBegin>
        <processor type="Abc.SharedSource.SitecoreProcessors.BasicAuthentication, BrookfieldResidential.Extensions"
						   patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.UserResolver, Sitecore.Kernel']"/>
      </httpRequestBegin>
    </pipelines>
    <settings localenv:require="DevBuild or LocalDeveloper">
      <setting name="TurnonBasicAuth" value="True"></setting>
      <setting name="ExcludedPaths" value="media,layouts,speak,/sitecore,/sitecore/admin,brpsc.dev.local/about" />
      <setting name="BasicAuthUsername" value="UserTest1,TestUser2,TesUser3" />
      <setting name="BasicAuthPassword" value="testpass1,testpass2,testpass3" />
    </settings>
  </sitecore>
</configuration>

You should then get the default login screen that looks like this:

Updating #Sitecore 9 Update 1 to Update 2

I am always a little hesitant going from one Sitecore version to another, but with Sitecore 9 I believe it is a straightforward process. Using the Sitecore package updater simplified things. Steps and pictures below.

In the control panel choose Install an Update.

Choose your package and upload.

Click the Analyze the Package brings up this screen:

I then clicked the Analyze green arrow. The following screen appears.

Some of the conflicts were spaces or things that I could skip. If it was a configuration change I still needed a patch was created. Really nothing too major.

That was it for me. There are some minor things that might need to be adjusted. Keep in mind that you will need to update NuGet packages in your Sitecore Visual Studio solution. Also, any config and pipeline changes that might be different.

Upgrading to #Sitecore 9 Data Exchange Framework Module 2.0.1. What to Expect. #DEF

In last year’s blogs I did a several part series on the Data Exchange Framework or DEF. You can find that here. I decided to upgrade my DEF Reddit feed module to the latest versions of Sitecore and DEF to get more familiar with the changes.

The first thing I did to the solution after installing the new latest version of DEF into Sitecore 9 Update 1 was to replace the following files.

Code Changes:

Starting with BaseReadDataStepProcessor I noticed a slight change.

The following code:

protected override void ReadData(Endpoint endpoint, Sitecore.DataExchange.Models.PipelineStep pipelineStep, PipelineContext pipelineContext) {  

Should now be:

protected override void ReadData(Endpoint endpoint, PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger) {  

As you can see from the above code PipelineContext was replaced with ILogger.

The function that adds the plugin has changed.

From this:

pipelineContext.Plugins.Add(dataSettings);  

To this:

pipelineContext.AddPlugin(dataSettings);  

In the RedditFeedValueReader the following method has changed since CanReadResult object is now ReadResult,

Original:

  1. public CanReadResult CanRead(object source, DataAccessContext context) {  
  2.     bool flag = source != null && source is RedditSharp.Things.Post;  
  3.     return new CanReadResult() {  
  4.         CanReadValue = flag  
  5.     };  
  6. }  

    Change:

  7. public ReadResult CanRead(object source, DataAccessContext context) {  
  8.     bool flag = source != null && source is RedditSharp.Things.Post;  
  9.     return new ReadResult(DateTime.Now) {  
  10.         ReadValue = source, WasValueRead = flag,  
  11.     };  
  12. }

    In the RedditFeedFieldValueAccessorConverter class I noticed the following issue after upgrading.


    After using DotPeek to take a look I found this method no longer exists. It looks like it has been renamed/replaced by ConvertResult. Also it has been set to protected vs public.

  13. protected override ConvertResult < IValueAccessor > ConvertSupportedItem(ItemModel source) {  
  14.     return this.PositiveResult((IValueAccessor) new ValueAccessor() {  
  15.         ValueReader = this.GetValueReader(source), ValueWriter = this.GetValueWriter(source)  
  16.     });  
  17. }  

    So, I converted by existing method and it works again.

  18. protected override ConvertResult < IValueAccessor > ConvertSupportedItem(ItemModel source) {  
  19.     var accessor = base.Convert(source);  
  20.     if (accessor == null) {  
  21.         return null;  
  22.     }  
  23.     var fieldName = base.GetStringValue(source, RedditFeedFieldValueValueAccessorItemModel.RedditFeedFieldName);  
  24.     if (string.IsNullOrEmpty(fieldName)) {  
  25.         return null;  
  26.     }  
  27.     if (string.IsNullOrEmpty(fieldName)) {  
  28.         return null;  
  29.     }  
  30.     ValueWriter = this.GetValueWriter(source);  
  31.     ValueReader = this.GetValueReader(source) ? ? new RedditFeedValueReader(fieldName);  
  32.     if (ValueWriter == null) {  
  33.         ValueWriter = new PropertyValueWriter(fieldName);  
  34.     }  
  35.     return this.PositiveResult((IValueAccessor) new ValueAccessor());  
  36. }  

    The way ids were set before is now a bit different.

    Before I would set id’s using the following:

  37. private¬†static¬†readonly¬†Guid¬†TemplateId¬†=¬†Guid.Parse(“{CE67E73A-40DF-4AB7-A7D3-2FD65E166E2E}”);¬†¬†
  38. public RedditEndpointConverter(IItemModelRepository repository): base(repository) {  
  39.     this.SupportedTemplateIds.Add(TemplateId);  
  40. }  

    I changed that and now just do this:

  41. [SupportedIds(“{68BD9AAD-635F-40F3-9ACD-711662C59EEC}”)]¬†¬†

    Sitecore Changes:

    The value mapping has changed to a Treelist instead of a droplist.

    The window that gave you updates while the batch process ran has changed. Now it links to a log file.


    Those are the changes I made for now. Unfortunately, I am not able to run the process as I did before. It seems something else has changed. I am currently digging into that and have gone to Sitecore support for help. I will document the change in my next blog and also update the code repository so you can see the new changes.

Named a #SitecoreMVP 2018 MVP Technology

As I am writing this I am still in shock. Several years ago I was just learning and developing with Sitecore at night while working on other projects during the day. Little did I know where it would lead me. I have run several marathons and I can tell you this journey was a marathon. There were some good and rough times along my way, but I kept moving forward.

My drive to become an MVP started a year ago when I got a job with Paragon and they gave me the confidence to believe I can achieve MVP status. I talked to many MVPs this past year and they gave me a lot of helpful advice. I have met so many people in the Sitecore community this past year as well and I am excited about being more involved in the community as an MVP and making new connections. The highlights of this year have been the meetups, Slack conversations and most of all getting to attend the Sitecore Symposium in Las Vegas. So, I just want to say thank you to Paragon, all the MVPs who gave me advice, aspiring MVPs that were on the ride with me, Sitecore of course and the Sitecore community.

So now what? Well no matter what if I didn’t get awarded MVP I was going to continue doing what I am doing. I learned a lot about myself this past year. I love blogging, I really love Sitecore more than I realized before and most of all I love sharing my knowledge. If I was going to add something new I think it would be coming up with a YouTube video this year. I just need to find the right blog topic.

To see all the winners check it out here. Also congratulations to my co-worker Scott Gillis who has gotten Sitecore MVP for the second year in year in a row. You can check his blog at thecodeattic.

 

First Ever Milwaukee Meets Chicago #Sitecore Meetup Recap

So not sure exactly who’s idea it was, but it turned out to be a great one to combine the Milwaukee Sitecore Meetup with the Chicago Sitecore meetup. No Bears vs Packers football was discussed, just Sitecore. There must have been over 30 attendees. Coveo did the first presentation and I was honored to be part of the second presentation of Sitecore Symposium attendees. I can’t wait for the next one. So here is the recap in pictures.

I live in the far west suburbs of Chicago so driving to Kenosha, Wisconsin was about the same time as it took me to get to the Chicago meetups. I enjoyed my view of the country roads and put on some classic hard rock music.

I arrived at the venue. I have never been to the Brat Stop, but I may have to come back for a visit.


Upon arrival it was great to start meeting others in person and seeing people again that I have met at the Symposium, the Chicago meetups and even one of my co-workers in person.

Renee from American Eagle and Isabel from Coveo.

My co-worker Chad from Paragon and Joe from GeekHive.

Like I said a sizable number of attendees.

Look at that food. Not bad for not being Chicago pizza.

I always love Sitecore freebies. I do love Sitecore like the pin says.

So let’s get down to the meetup itself. It first started with all the sponsors telling a little about the company they work for. I talked about Paragon and what we did. Hopefully what I was saying made sense. I am a developer, but I always try and do my best to sell.

Coveo then did a presentation. Coveo has been a huge part of Sitecore searching/marketing and they always impress me. I can’t wait to do another project with their tools.

 

 

 

 

 

 

 

 

 

Now it was time for the Sitecore Symposium panel.

110317_1718_FirstEverMi11.jpg

We all gave our best insights and reported things we learned and brought up a lot of subjects. Mark and the audience had some great questions. This was so much fun.

So when is the next one? Not sure, but this one was so much fun. Maybe we can discuss Bears vs Packers at the next one?

So That is What the Custom Data Property is for. #Sitecore #Hedgehog #TDS and Glass Mapper Model Generation.

Glass and TDS makes our development life easier so we should try and use every feature we can. Right? One of my favorite features is generating a list of Glass models instead of GUIDS. A lot of you probably know this, but there is always times where someone does not. I wanted to document this so this can help others.

Select the field that is a Treelist or whatever multi list field.

In the properties under Code Generation you need to specify the type of list you want returned with model.

In my case:

type=IEnumerable<Feature.SectionLink.Models.sitecore.templates.Feature.SectionLink.SectionLink>.

Now Glass will auto generate and you will get the actual Glass Item Model instead a list of GUIDS.

[SitecoreType(TemplateId=ISectionLinksConstants.TemplateIdString)]

public partial class
SectionLinks  : GlassBase, ISectionLinks

       {

///
<summary>

 /// The Section List field.

            ///
<para></para>

                           ///
<para>Field Type: Treelist</para>          

                           ///
<para>Field ID: e09af999-37fa-42a3-98b7-1ffb802413c2</para>

                           ///
<para>Custom Data: type=IEnumerable<Feature.SectionLink.Models.sitecore.templates.Feature.SectionLink.SectionLink></para>

                           ///
</summary>

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† ¬†¬†¬†¬†¬†¬† [global::System.CodeDom.Compiler.GeneratedCodeAttribute(“Team Development for Sitecore – GlassItem.tt”, “1.0”)]

                           [SitecoreField(ISectionLinksConstants.Section_ListsFieldName)]

                           public
virtual
IEnumerable<Feature.SectionLink.Models.sitecore.templates.Feature.SectionLink.SectionLink> Section_Lists  {get; set;}

       }

In my controller I just call it this way and I have my list to run through the ForEach:

viewModel = sitecoreservice.Cast<ISectionLinks>(Sitecore.Context.Item,inferType:true).Section_Lists.ToList();

So that is it. Let me know if there is something else we can do with this property. I would like to know.

#Sitecore Data Exchange Framework Scheduling Tasks Options

One of the little known things that comes with the DEF is new commands that can be used to schedule DEF pipeline batches.

The new command options under System/Tasks/Commands/Data Exchange are the following:

  • Run All Pipeline Batches Command (Used to run multiple batches.)
  • Run Selected Pipeline Batches Command (Used to run one batch process.)

Run All Pipeline Batches Command

This command is used for running multiple batch processes. You will notice in the Pipeline Batches Root I just selected the Pipeline Batches parent folder. This should run all the batch processes underneath it.

Run Selected Pipeline Batches Command

With this command you can select one Batch Process to run.

Scheduling

Once you have your commands setup scheduling is easy. Just create a scheduling task and select the command and fill in the required fields like you would do for other commands.

That’s it. Easy to schedule.

#Sitecore ‘s SaveUI Pipeline One Way it Can Save You from the Cache

Recently I had a bug fix that required fixing a custom tab page in the content editor. The custom page had a save button, but users were also clicking on the content editor save button. Well unfortunately that undid the previous change. The reason why was even though the changes were saved to the database the old values were still being cached.

So after doing some research on maybe refreshing, clearing cache etc… the best way to fix this issue turned out to be was adding a custom pipeline step on the SaveUI pipeline. It was a little a trial and error at first, but I was able to accomplish what I needed to.

First thing is you want to do is come up with a name for your new class and create a config file that will hook into the SaveUI pipeline. Now you have some options here. If you look below the SaveUI has a series of steps that happen in order for an item to save. You just need to find the one you want your step to go before or after.

<saveUI>
<processor mode=”on” type=”Sitecore.Pipelines.Save.BeforeSaveEvent, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ParseXml, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckItemLock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckRevision, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Validators, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ValidateFields, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.HasWritePermission, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.NewVersion, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.TightenRelativeImageLinks, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ConvertToXHtml, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckLock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Lock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckBaseTemplateFieldChange, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckTemplateFieldChange, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ConvertLayoutField, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckLinks, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Save, Sitecore.Kernel” />
<processor mode=”off” type=”Sitecore.Pipelines.Save.RenderingHack, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Unlock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.WorkflowSaveCommand, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.PostAction, Sitecore.Kernel” />
</saveUI>

I created a config file and placed it in the app_config\include folder of the website.

<configuration xmlns:patch=”http://www.sitecore.net/xmlconfig/”&gt;
<sitecore>
<processors>
<saveUI>
<processor patch:before=”processor[@type=’Sitecore.Pipelines.Save.CheckRevision, Sitecore.Kernel’]” type=”MySite.Feature.Website.Pipelines.ConfirmChanges,MySite.Feature.Website” />
</saveUI>
</processors>
</sitecore>
</configuration>

The code for the pipeline was simple. Basically I would check for what fields changed and made sure what was saved in the database fields would update the fields in the cache. That way when the save happens the SaveUI pipeline will process the changes and not overwrite anything.

public class ConfirmChanges
{
public void Process(SC.Pipelines.Save.SaveArgs args)
{
Assert.ArgumentNotNull(args, “args”);

if (!args.HasSheerUI)
{
return;
}

Assert.IsNotNull(SC.Context.ContentDatabase, “Sitecore.Context.ContentDatbabase”);
string message = string.Empty;

// for each of the items the user attempts to save
foreach (SC.Pipelines.Save.SaveArgs.SaveItem uiItem in args.Items)
{
// retrieve from the database the same item containing the old values
SC.Data.Items.Item dbItem = SC.Context.ContentDatabase.GetItem(uiItem.ID, uiItem.Language, uiItem.Version);
Assert.IsNotNull(dbItem, “dbItem”);

// for each of the fields in that item (not just updated fields)
if (UsesCustomTab(dbItem))
{
foreach (SC.Pipelines.Save.SaveArgs.SaveField uiField in uiItem.Fields)
{
if (uiField.Value == dbItem[uiField.ID])
{
continue;
}
string title = string.IsNullOrEmpty(dbItem.Fields[uiField.ID].Title)
? dbItem.Fields[uiField.ID].DisplayName
: dbItem.Fields[uiField.ID].Title;
if (title == “FieldName1” || title == “FieldName2”)
{
//if values are the same don’t do anything exit pipeline.
if (!string.IsNullOrEmpty(dbItem[uiField.ID]) && dbItem[uiField.ID] == uiField.Value)
{
continue;
}
else
{
if (title == “FieldName1”)
{
uiField.Value = dbItem.Fields[“FieldName1”].Value;
}
if (title == “FieldName2”)
{
uiField.Value = dbItem.Fields[“FieldName2”].Value;
}
}

}
}
}
}

}
}

That’s it. Let me know if you have any questions.

cache