Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:36:30+00:00 2026-06-17T21:36:30+00:00

When I manually archive an item which is referenced by other items Sitecore popup

  • 0

When I manually archive an item which is referenced by other items Sitecore popup dialog box with Actions – how to handle the links.

If the item is configured for automatic archiving with “Set Archive Date” and it is archived seems that Sitecore is choosing by default “Leave Links” action, so all links to the archived item will be broken.

How/Where could I hooked up in order to stop archiving of item (scheduled archiving) which is referenced by other items? I would like to stop archiving and create some rapport that that archiving was not successful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:36:31+00:00Added an answer on June 17, 2026 at 9:36 pm

    In order to prevent Sitecore from archiving linked items, you need to overrider 2 classes.
    First of them is ArchiveItem so it’s checking whether item is linked before archiving it:

    namespace My.Assembly.And.Namespace
    {
        public class MyArchiveItem : Sitecore.Tasks.ArchiveItem
        {
            public MyArchiveItem(System.DateTime taskDate) : base(taskDate)
            {
            }
    
            public override void Execute()
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    lock (SyncRoot)
                    {
                        Sitecore.Data.Items.Item item = GetItem();
                        if (item != null && HasLink(Sitecore.Globals.LinkDatabase, item))
                        {
                            Sitecore.Diagnostics.Log.Error(string.Format(
                                "Item {0} or one of its descendants are linked from other items. "
                                + "Remove link before scheduling archive.", item.Paths.FullPath), this);
                            // uncomment next line if you don't want to retry archiving attempt
                            //Sitecore.Globals.TaskDatabase.Remove(this);
                            return;
                        }
                    }
                }
                base.Execute();
            }
    
            private static bool HasLink(Sitecore.Links.LinkDatabase linkDatabase, Sitecore.Data.Items.Item item)
            {
                Sitecore.Links.ItemLink[] referrers = linkDatabase.GetReferrers(item);
                if (referrers.Length > 0)
                {
                    if (referrers.Any(link => link.SourceFieldID != Sitecore.FieldIDs.Source))
                    {
                        return true;
                    }
                }
                foreach (Sitecore.Data.Items.Item item2 in item.Children)
                {
                    if (HasLink(linkDatabase, item2))
                    {
                        return true;
                    }
                }
                return false;
            }
        }
    }
    

    Second class which you need to override is SqlServerTaskDatabase so it schedules the overriden MyArchiveItem task instead of the original Sitecore ArchiveItem:

    namespace My.Assembly.And.Namespace
    {
        public class MySqlServerTaskDatabase : Sitecore.Data.SqlServer.SqlServerTaskDatabase
        {
            public MySqlServerTaskDatabase(string connectionString) : base(connectionString)
            {
            }
    
            public override void UpdateItemTask(Sitecore.Tasks.Task task, bool insertIfNotFound)
            {
                Sitecore.Data.Sql.SqlBatch batch = new Sitecore.Data.Sql.SqlBatch(true);
                BindTaskData(task, batch);
                string sql = GetUpdateSql() + 
                    " WHERE [ItemID] = @itemID AND [Database] = @databaseName AND [taskType] = @taskType";
                batch.AddSql(sql);
                if (insertIfNotFound)
                {
                    AddInsertTask(batch, true);
                }
                batch.Execute(ConnectionString);
            }
    
            protected new virtual void BindTaskData(Sitecore.Tasks.Task task, 
                Sitecore.Data.Sql.SqlBatch batch)
            {
                System.DateTime taskDate = task.TaskDate;
                if (taskDate == System.DateTime.MinValue)
                {
                    taskDate = (System.DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
                }
                batch.AddParameter("taskID", task.ID);
                batch.AddParameter("nextRun", taskDate);
                if (task is Sitecore.Tasks.ArchiveItem)
                {
                    batch.AddParameter("taskType",
                        Sitecore.Reflection.ReflectionUtil.GetTypeString(typeof(MyArchiveItem)));
                }
                else
                {
                    batch.AddParameter("taskType", ReflectionUtil.GetTypeString(task.GetType()));
                }
                batch.AddParameter("parameters", task.Parameters);
                batch.AddParameter("recurrence", task.RecurrencePattern);
                batch.AddParameter("itemID", task.ItemID);
                batch.AddParameter("databaseName", task.DatabaseName);
                if (string.IsNullOrEmpty(task.InstanceName))
                {
                    batch.AddParameter("instanceName", System.DBNull.Value);
                }
                else
                {
                    batch.AddParameter("instanceName", task.InstanceName);
                }
            }
        }
    }
    

    The last thing you need to do is to update Sitecore config to point at MySqlServerTaskDatabase:

    <TaskDatabase type="My.Assembly.And.Namespace.MySqlServerTaskDatabase, My.Assembly">
        <param connectionStringName="core"/>
    </TaskDatabase>
    

    The information about failed archiving attempt will be stored in log files. You may want to update this part to store it in your custom reports.


    Below goes additional information which is not necessary for your original problem to work.

    You can also hook before the schedule is set as described below to inform user that the item won’t be archived.

    First create the class that will override ArchiveDateForm class:

    namespace My.Assembly.And.Namespace
    {
        public class MyArchiveDateForm
            : Sitecore.Shell.Applications.Dialogs.ArchiveDate.ArchiveDateForm
        {
            protected override bool SetItemArchiveDate
                (Sitecore.Data.Items.Item item, string value)
            {
                if (HasLink(Sitecore.Globals.LinkDatabase, item))
                {
                    Sitecore.Web.UI.Sheer.SheerResponse.Alert(
                        "Item or one of its descendants are linked from other items. "
                        + "Remove link before scheduling archive.", new string[0]);
                    return false;
                }
                return base.SetItemArchiveDate(item, value);
            }
    
            private static bool HasLink(Sitecore.Links.LinkDatabase linkDatabase,
                Sitecore.Data.Items.Item item)
            {
                Sitecore.Links.ItemLink[] referrers = 
                    linkDatabase.GetReferrers(item);
                if (referrers.Length > 0)
                {
                    if (referrers.Any(
                        link => link.SourceFieldID != Sitecore.FieldIDs.Source))
                    {
                        return true;
                    }
                }
                foreach (Sitecore.Data.Items.Item item2 in item.Children)
                {
                    if (HasLink(linkDatabase, item2))
                    {
                        return true;
                    }
                }
                return false;
            }
    
        }
    }
    

    Then find the file /sitecore/shell/applications/dialogs/archive item/archive date.xml. Change the 6th line to point at the new class:

    <CodeBeside Type="My.Assembly.And.Namespace.MyArchiveDateForm,My.Assembly" />
    

    And that’s it. Whenever one will try to schedule archiving of an linked item, Sitecore will display information that the item cannot be archived.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I handle manually the 404 error in C#? I want to check
I have an archive, which is archived by someone else, and I want to
Manually built: [btnRun addTarget:self action:@selector(RunApp:) forControlEvents:UIControlEventTouchUpOutside]; Programmatically built: something of the following like ??
Does it need manually close InputStream (bean.getContentAsStream()) in java after pass to Spring JDBC
Do we need to manually import in main project the user location graphical assets
I am currently manually managing the lifecycle of objects in my project. I am
I am able to manually get the user's data, but not programatically. Using the
I want to manually create a ID field where I do MAX + 1,
I can create database manually by going to cpanel. But I'd like to create
How do I manually touch a UIView means programattically. I want to touch a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.