I have a requirement where I have to clean up the draft items in sitecore workbox which are there for more than two years in workbox. Can anybody tell me from where/how to start and how to access items from sitecore workbox programmatically?
1 Answer
You can gain access to the workbox items by using the WorkflowProvider. If you already know what is the workflow id, you can use the following to get the IWorkflow
. This will allow you to access the item states.
var masterContents= Factory.GetDatabase("master").WorkflowProvider.GetWorkflow("Your Workflow ID");
Then, from the masterContents
you can retrieve all the items that match a state id. The state id is the item id of the draft
item.
var masterContents= Factory.GetDatabase("master").WorkflowProvider.GetWorkflow("Your Workflow ID");
var draftItems = masterContents.GetItems("your draft item id");
foreach (var draftItem in draftItems)
{
//TODO - Remove the item version here
}
The draftItems
returns a list of DataUri
which allows you to access the specific item version, language etc.
foreach (var draftItem in draftItems)
{
var item = Factory.GetDatabase("master").GetItem(draftItem.ItemID, draftItem.Language, draftItem.Version);
item.RecycleVersion();
}
Note that I have not yet tested the code but this is the basic idea how to do it.
-
Thanks so much for the quick response!!! I will definitely try these steps out and update my comments here. But I have got the core idea of how & where to start.– HarishCommented Nov 19, 2020 at 15:40
-
I have approved, also I tried to upvote but somehow its not getting increased.– HarishCommented Nov 19, 2020 at 18:46