In one of our projects, we are facing an issue where our item is in draft state but it is published to the web while our custom code is called. However, in the case of normal publishing, it is respecting the workflow. So the question is, why is it not respecting the workflow state while using custom code? Below is the sample code screenshot.:
2 Answers
There is a similar kind of question available in this URL please take a look
If we try with the Sitecore Shell site context this issue of publishing draft items will be ignored.
using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("shell")))
{
//publishing logic
}
or
using (new SiteContextSwitcher(SiteContext.GetSite("shell")))
{
// do publishing logic
}
-
Thanks for your response this really work for us. Really apricated.Arun Sharma– Arun Sharma2025-02-05 07:25:22 +00:00Commented Feb 5 at 7:25
You fail to mention how you're executing your custom code. But it does look like code that might be executed as a scheduled task or something similar.
Something to be aware of when you do this; these jobs run in the context of the "scheduler" site. And that site does not respect workflows. You need to either select a different site to run in context of; or set the "scheduler" site to enableWorkflows=true in your site configuration.
You never need to manually check for workflow state; this would be an unsupported approach to solving the problem.
-
Thanks for your response, I got an idea why this issue arise . :)Arun Sharma– Arun Sharma2025-02-05 07:24:54 +00:00Commented Feb 5 at 7:24
