1

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?

2
  • By cleanup, do you mean remove or approve that version? Nov 19 '20 at 15:16
  • we need to remove that version which is in draft.
    – Harish
    Nov 19 '20 at 15:17
1

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.

2
  • 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.
    – Harish
    Nov 19 '20 at 15:40
  • I have approved, also I tried to upvote but somehow its not getting increased.
    – Harish
    Nov 19 '20 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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