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

  • SEARCH
  • Home
  • 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 6572307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:59:21+00:00 2026-05-25T14:59:21+00:00

I’m working on a mechanism to change and items Icon based on a check

  • 0

I’m working on a mechanism to change and items Icon based on a check on a field of that item. If the Referencefield I’m checking has a targetItem and the targetItem has content I want the icon of the item I’m saving to be changed. This is my current code:

Sitecore.Data.Items.Item currentItem = Sitecore.Events.Event.ExtractParameter(args, 0) as Sitecore.Data.Items.Item;

if (ValidForIconChange(currentItem))
{
    using (new EventDisabler())
    {
        if (HelperClasses.SharedContentHelper.itemHasSharedContent(currentItem))
        {
            currentItem.Editing.BeginEdit();
            currentItem.Appearance.Icon = "Applications/32x32/document_out.png";
            currentItem.Editing.EndEdit();
        }
        else
        {
            currentItem.Editing.BeginEdit();
            currentItem.Appearance.Icon = currentItem.Template.Icon;
            currentItem.Editing.EndEdit();
        }
    }

    RefreshScreen(currentItem);                
}

And the helper functions:

    /// <summary>
    /// Checks if the item is valid to change the icon of the item
    /// </summary>
    /// <param name="currentItem">The current item.</param>
    /// <returns></returns>
    private static bool ValidForIconChange(Sitecore.Data.Items.Item currentItem)
    {
        return currentItem != null && ItemHelper.DoesItemImplementTemplate(currentItem, "_gedeelde inhoud") && currentItem.Language.Name == "nl-NL";
    }

    /// <summary>
    /// Refreshes the screen.
    /// </summary>
    /// <param name="currentItem">The current item.</param>
    private void RefreshScreen(Sitecore.Data.Items.Item currentItem)
    {
        if (Sitecore.Context.ClientPage != null)
        {
            if (currentItem.Parent != null)
            {
                if (!currentItem.Editing.IsEditing)
                {
                    //TODO: set to the appropriate item 
                    String refresh = String.Format("item:refreshchildren(id={0})", currentItem.Parent.ID);
                    Sitecore.Context.ClientPage.SendMessage(this, refresh); 
                }                                       
            }
        }
    }

Currently I’m just guessing around a bit on how to work with this event. Basicly I´m trying to find out on how to work with the EventDisabler, cause I want to raise my own event for updating the parents children after I´ve changed the icon, but this gives me trouble for when I´m publishing the website. I think I haveto know when I´m working with a publish action instead of a single item save. I want this code only to be triggered when really just saving an item and not when publishing the website. Publish actions result in the following error (which I assume are because I disable events, and after publishing an event is raised):

Job started: Publish to 'web'|Items created: 0|Items deleted: 0|Items updated: 1|Items skipped: 0|Job ended: Publish to 'web' (units processed: 1)|Job started: Publish to 'web'|#Exception: System.Reflection.TargetInvocationException: Het doel van een aanroep heeft een uitzondering veroorzaakt. ---> System.NullReferenceException: De objectverwijzing is niet op een exemplaar van een object ingesteld.
   bij Sitecore.Web.UI.Sheer.ClientPage..ctor()
   bij Sitecore.Context.get_ClientPage()
   bij CommandTemplates.Classes.SharedContentIconChanger.RefreshScreen(Item currentItem)
   bij CommandTemplates.Classes.SharedContentIconChanger.OnItemSaved(Object sender, EventArgs args)
   bij Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters, EventResult result)
   bij Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters)
   bij Sitecore.Events.Event.RaiseEvent(String eventName, Object[] parameters)
   bij Sitecore.Events.Event.RaiseItemSaved(Object sender, ItemSavedEventArgs args)
   bij Sitecore.Events.Event.DataEngine_ItemSaved(Object sender, ExecutedEventArgs`1 e)
   bij System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   bij Sitecore.Data.Engines.EngineCommand`2.RaiseExecuted()
   bij Sitecore.Data.Engines.EngineCommand`2.Executed()
   bij Sitecore.Data.Engines.EngineCommand`2.Execute()
   bij Sitecore.Data.Engines.DataEngine.SaveItem(Item item)
   bij Sitecore.Data.Managers.ItemProvider.SaveItem(Item item)
   bij Sitecore.Data.Managers.ItemManager.SaveItem(Item item)
   bij Sitecore.Data.Items.ItemEditing.AcceptChanges(Boolean updateStatistics, Boolean silent)
   bij Sitecore.Data.Items.ItemEditing.EndEdit(Boolean updateStatistics, Boolean silent)
   bij Sitecore.Data.Items.EditContext.Dispose()
   bij Sitecore.Publishing.PublishHelper.CopyToTarget(Item sourceVersion)
   bij Sitecore.Publishing.PublishHelper.PublishVersionToTarget(Item sourceVersion, Item targetItem, Boolean targetCreated)
   bij Sitecore.Publishing.PublishHelper.PublishVersion(Item sourceVersion)
   bij Sitecore.Publishing.Pipelines.PublishItem.PerformAction.PublishVersion(PublishItemContext context)
   bij Sitecore.Publishing.Pipelines.PublishItem.PerformAction.ExecuteAction(PublishItemContext context)
   bij Sitecore.Publishing.Pipelines.PublishItem.PerformAction.Process(PublishItemContext context)
   bij (Object , Object[] )
   bij Sitecore.Pipelines.PipelineMethod.Invoke(Object[] parameters)
   bij Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   bij Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   bij Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args)
   bij Sitecore.Publishing.Pipelines.PublishItem.PublishItemPipeline.Run(PublishItemContext context)
   bij Sitecore.Publishing.Pipelines.Publish.ProcessQueue.ProcessEntries(IEnumerable`1 entries, PublishContext context)
   bij Sitecore.Publishing.Pipelines.Publish.ProcessQueue.Process(PublishContext context)
   bij (Object , Object[] )
   bij Sitecore.Pipelines.PipelineMethod.Invoke(Object[] parameters)
   bij Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   bij Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   bij Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args)
   bij Sitecore.Publishing.Pipelines.Publish.PublishPipeline.Run(PublishContext context)
   bij Sitecore.Publishing.Publisher.PerformPublish()
   bij Sitecore.Publishing.Publisher.Publish()
   --- Einde van intern uitzonderingsstackpad ---
   bij System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   bij System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   bij System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   bij Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)
   bij Sitecore.Reflection.MethodInstance.Invoke()
   bij Sitecore.Jobs.JobRunner.RunMethod(JobArgs args)
   bij (Object , Object[] )
   bij Sitecore.Pipelines.PipelineMethod.Invoke(Object[] parameters)
   bij Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   bij Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
   bij Sitecore.Jobs.Job.ThreadEntry(Object state)

Anyone here have an idea on a different approach or any tips?
Thanks!

  • 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-05-25T14:59:21+00:00Added an answer on May 25, 2026 at 2:59 pm

    Solved this issue by checking wheter item:saved was called by publishing or just by saving the item:

    if(Sitecore.Context.Job != null &&Sitecore.Context.Job.Category == "publish") 
    {
      // Do nothing
    } else {
      // Change Icon code here`enter code here`
    }
    

    This way you can determine if you’re in the proces of publishing.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.