Skip to content
August 29, 2014 / kiranpatils

Call External WebService If Item is REALLY Published


We were working on an interesting task. We’ve tree structure similar like this :

Scenario-v1Now, each product has retailers mapped to them, which gets stored in different system – To update that we’ve to call a Web Service and pass all the mapped retailers for particular product on PUBLISH – But we’ve to make sure that ONLY if the Item which is getting published should be of type PRODUCT. Sounds good?! Clear? Now, what you will use? Did you say publish:end? If yes, then we also thought it and gave it a try. It works fine when you publish an individual item. BUT what If when someone published root folder Products with Sub-items? If you said that If Current Publish Item is /Products/ then get all descendants and call web service for each one correct? Yes, it will work! But, let me add one more twist. What If, Someone did a Smart Publish? – Now, only products which has been updated and REALLY Got Published for them only Web Service should get called? I know you like the challenges! So, as we! We found a way [“A will will find a way!“]

Eager to know?! Here we go!

Solution :

Before we move ahead to the solution. I would recommend you to read following blog posts. They are Bible on Sitecore Publishing Pipelines:


In the past when we were dealing with publishing challenges, We used Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics pipeline to understand whether current item got published or skipped by making traceToLog to true

<processor type="Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics, Sitecore.Kernel" runIfAborted="true">

And having this knowledge gave us a pointer to look in to. So, we just asked our common friend Reflector to show us what code lies within Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics.UpdateContextStatistics method, Which uses this code PublishItemResult result = context.Result;  PublishItemResult Class has property named as Operation which is of Type PublishOperation enum and it has following possible values:

public enum PublishOperation
    None, // Same as Skipped
    Skipped,// If Item has been skipped during publishing operation
    Created, // If Item has been created during publishing operation
    Updated, // If Item has been updated during publishing operation
    Deleted // If Item has been deleted during publishing operation


And here’s how the final code looks like:

   public class BasicUpdateRetailer
       : Sitecore.Publishing.Pipelines.PublishItem.PublishItemProcessor
    public override void Process(Sitecore.Publishing.Pipelines.PublishItem.PublishItemContext context)
        PublishItemResult result = context.Result;
        Item itemToPublish = context.PublishHelper.GetItemToPublish(context.ItemId);
        if ((result != null) && (context != null))
            switch (result.Operation)
                case Sitecore.Publishing.PublishOperation.Created:
                case Sitecore.Publishing.PublishOperation.Updated:
                    if (itemToPublish.IsProduct())
                        Item[] targetItems = null;
                        MultilistField multilistField = itemToPublish.Fields["RETAILERSFIELD"];
                        if ((multilistField != null) && (multilistField.InnerField != null))
                            targetItems = multilistField.GetItems();

                        if (targetItems != null && targetItems.Any())
                            // Call WebService and do update
                case Sitecore.Publishing.PublishOperation.Deleted:
                case Sitecore.Publishing.PublishOperation.None:
                case Sitecore.Publishing.PublishOperation.Skipped:

Yes, As you rightly said we need to add our PublishItem Processor via configuration:

        <processor patch:before="processor[@type='Sitecore.Publishing.Pipelines.PublishItem.UpdateStatistics, Sitecore.Kernel']"
                   type="Sitecore.Basics.Pipelines.PublishItem.BasicUpdateRetailer, Sitecore.Basics.Pipelines" />

You know other better way? Or you were looking for something and this helped? Feel free to share your learning(s) with us!

Good Reads:


Happy Publishing! 🙂



Leave a Comment
  1. test / Sep 14 2014 4:25 pm


    • kiranpatils / Sep 14 2014 4:31 pm

      Whomsoever you are — Your test is successful! 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: