1

Working in Sitecore 10.2, we have a new site that we've added custom processors to to update fields on item:save that need to be automatically generated. We have a very simple processor that sets a custom Calculated Statistics field to an ISO date (as well as other processors that are likely causing the same issue, but I've been able to replicate the issue with only this one processor in place).

Although the only thing the processor does is set a field value, when it does so, the __Final Renderings field never gets set (so all rendering parameters in the standard values don't show up on the page).

namespace MySite.Project.ItemSaving
{
    public class ItemSavingCalculatedStatistics
    {
        public void OnItemSaving(object sender, EventArgs args)
        {
            var savingItem = Event.ExtractParameter(args, 0) as Item;
            Error.AssertNotNull(savingItem, "No item in parameters");
            if (savingItem == null)
            {
                // not for us
                return;
            }

            if (!savingItem.DescendsFrom(FoundationTemplateConstants.CalculatedStatistics.CalculatedStatisticsTemplateId))
            {
                return;
            }

            try
            {
                var statisticsUpdated = savingItem.Statistics.Updated;
                var field = savingItem.Fields[FoundationTemplateConstants.CalculatedStatistics.Fields.CalculatedStatisticsUpdated];
                if (field != null) field.Value = DateUtil.ToIsoDate(statisticsUpdated);
            }
            catch (Exception ex)
            {
                Log.Error("ItemSavingCalculatedStatistics ERROR...", ex, this);
            }
        }
    }
}

When I disable this processor, the __Final Renderings gets populated as expected; Likewise, when I simply put return at the very beginning of the processor, it's fine. It's only when we do if (field != null) field.Value = DateUtil.ToIsoDate(statisticsUpdated); that the page ends up having no Final Renderings.

I tried moving the processor to the very end of item:saving by naming prefixing the config file with zzz and inserting after the very last processor in the section, but the issue still occurs.

With the pipeline disabled: enter image description here

With the pipeline enabled: enter image description here

1
  • The issue is that on our branch templates, getting the savingItem with Event.ExtractParameter(args, 0) as Item was interfering with the initial page creation from branch templates. Basically, these pipelines have to NOT be run when creating an item from a branch template. We fixed this by returning null (and exiting the pipeline) when !string.IsNullOrWhiteSpace(layoutField?.Value) && !ID.IsNullOrEmpty(savingItem.BranchId) Commented May 9, 2023 at 17:21

2 Answers 2

1

Creating an item:save event that gets the item being saved using Event.ExtractParameter(args, 0) as Item; interferes with the creation of items from branch templates. The pipelines needs to be aborted when an item is being created from a branch template:

Item savingItem = Event.ExtractParameter(args, 0) as Item;

// check for newly created page created from BranchTemplate
// do NOT interfere with the initial creation of a page
// Presentation details will not be created properly otherwise.
var layoutField = savingItem?.Fields[Sitecore.FieldIDs.LayoutField];
if (!string.IsNullOrWhiteSpace(layoutField?.Value) &&
    !ID.IsNullOrEmpty(savingItem.BranchId) &&
    savingItem.Children.Count == 0)
{
    // stop processing
    return null;
}
-1

It seems that the issue you're facing is related to the order of execution of processors in the item:saving pipeline in Sitecore 10.2. The __Final Renderings field not being populated correctly when your custom processor is active suggests that it might interfere with the rendering parameters set in the standard values.

To address this issue, you can try adjusting the order of execution of processors in the pipeline. You mentioned that you attempted to move the processor to the end of the pipeline by prefixing the config file with "zzz" and inserting it after the last processor, but it didn't resolve the problem. It's possible that the issue lies with the specific position within the pipeline where your processor is being executed.

Instead of relying solely on the file name prefix, you can explicitly specify the position of your processor using the patch:after or patch:before attributes in the configuration file. Locate the configuration file where your processor is defined and update it with the appropriate position:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <itemSaving>
        <processor type="MySite.Project.ItemSaving.ItemSavingCalculatedStatistics, MySite.Project" patch:after="processor[@type='Some.Other.Processor.Type, Some.Assembly']" />
      </itemSaving>
    </pipelines>
  </sitecore>
</configuration>

In the patch:after attribute, specify the processor type that should precede your custom processor in the pipeline. By specifying a specific processor, you ensure that your custom processor is placed after it in the pipeline and has a chance to properly update the field without interfering with the rendering parameters.

Make sure to replace 'Some.Other.Processor.Type, Some.Assembly' with the actual type and assembly of the processor that should come before your custom processor in the pipeline.

By explicitly setting the position of your processor, you can control the order of execution and ensure that it doesn't interfere with other processors responsible for rendering parameters in the __Final Renderings field.

2
  • Hi Vishal, as I mentioned I tried inserting it after the very last processor in the section, I used patch:after to make it the very last item in the pipeline which is what I meant by that. Even as the very last item it interferes and needs to be aborted Commented May 12, 2023 at 18:42
  • 1
    Hi Erica - Try to use a different event or pipeline: Instead of relying solely on the item:saving event, you can explore using a different event or pipeline that occurs after the __Final Renderings field is processed. For example, you could try the item:saved event or the uiSaved pipeline. Commented May 13, 2023 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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