Try our conversational search powered by Generative AI!

Manoj Kumawat
Feb 28, 2022
  1134
(1 votes)

Delayed content scheduled job events

Hello everyone,

Today I was working on content events that adds the products under the category. As soon as you publish the category that will trigger the publish event and associates the products with the category that is being saved. This is working perfectly. 

The other scenarios where this was needed as where a category is scheduled to be published at a particular future time then those products should be auto assigned as soon as category is published. Now this required publish events to be triggered. I thought the job that keeps running is "Publish Delayed Content Versions" should handle those events by itself but unfortunately that wasn't supported. 

Per many blog posts it was suggested to write your own scheduled job that does it, This is what I'm sharing with you. Hopefully, It saves some time for you in future.

So I ended up writing my own scheduled job that looks for delayed contents and publishes them - 

  private void PublishOnBehalfOf(ContentReference contentLink, string user)
        {
            IPrincipal currentPrincipal = Thread.CurrentPrincipal;
            try
            {
                Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(user), null);

                var content = _contentLoader.Get<ContentData>(contentLink).CreateWritableClone();

                if (content != null)
                {
                    _contentRepository.Save((content as IContent), EPiServer.DataAccess.SaveAction.Publish | EPiServer.DataAccess.SaveAction.SkipValidation, AccessLevel.NoAccess);
                }
            }
            finally
            {
                Thread.CurrentPrincipal = currentPrincipal;
            }
        }

Let me know if full code is required. Thanks a lot for reading.

Feb 28, 2022

Comments

Please login to comment.
Latest blogs
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024

The Experimentation Process

This blog is part of the series -   Unlocking the Power of Experimentation: A Marketer's Insight. Welcome back, to another insightful journey into...

Holly Quilter | May 16, 2024

Azure AI Language – Sentiment Analysis in Optimizely CMS

In the following article, I showcase how sentiment analysis, which is part of the Azure AI Language service, can be used to detect the sentiment of...

Anil Patel | May 15, 2024 | Syndicated blog