0

Publishing from Sitecore 10.3 to Edge

I have a custom pipeline that updates the Last Published field with in Sitecore. When I publish to the WEB, it works as expected, but when I publish to Experience Edge, it doesn't update the Sitecore field.

<pipelines>
  <publishItem>
    <processor patch:after="*[@type='Sitecore.Publishing.Pipelines.PublishItem.PerformAction, Sitecore.Kernel']" type="{Custom}_Sitecore.Pipelines.SetPublishDates, {Custom}"/>
  </publishItem>
</pipelines>

Goal: I want to update the first and last published dates when an item has been published.

I would be grateful if you could provide me with any information.

2
  • Are you saying that you want any publish event to update the Last Published field in Sitecore, whether publishing to web or edge? What are you using this info for? Just reference on the back end or for use on the front end? Feb 16 at 19:14
  • @MarcelGruber Our content authors use this information to determine when the content was first/last published to production. And the last published date is used by a custom service that sends an email to the content authors.
    – Sun
    Feb 16 at 20:07

1 Answer 1

1

You can follow workflow action to achieve your target.

Please follow below steps to achieve this.

  1. Create a ACTION (using template: /sitecore/templates/System/Workflow/Action) under the Final Workflow State
  2. Under Type String – set the namespace and class name
  3. Then write your custom code according to your requirement, below is sample code for reference you have to update it according to your requirement.
public class PublishedDate
    {
        private const String publishDate = "_publishDate";

        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.DataItem;

            if (args.ProcessorItem!= null)
            {
                WorkflowState state = item.Database.WorkflowProvider.GetWorkflow(item).GetState(item);
                if (state != null && state.FinalState)
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        using (new EditContext(item, false, false))
                        {
                            item.Editing.BeginEdit();
                            item[publishDate] = Sitecore.DateUtil.ToIsoDate(DateTime.Now);
                            item.Editing.EndEdit();
                        }
                    }
                }
            }
        }
    }

Hope this helps you.

1
  • Thank you @Rishi, for finding a workaround solution. It's working.
    – Sun
    Feb 19 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.