3

The ask is to show the following kind of message on the OnItemSaved event.

enter image description here

I am unable to show a similar custom message on the OnItemSaved event. I am always getting some default exception message. I tried achieving it by throwing the custom exception as:

throw new CustomException("Section heading cannot have more than 20 characters !");

Please let me know if I am missing something.

1

You need to create a custom processor in the experience editor or/and content editor based on your requirement. A simple way to create a custom patch config to register the processor and a class file with your code.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
      <sitecore>
         <pipelines>
            <!--Disyplay warning in the content editor-->
             <getContentEditorWarnings>
                      <processor type="xyz.Warning.YourClass, xyz" />
             </getContentEditorWarnings>

            <!--Disyplay warning in the Exprience editor-->
             <getPageEditorNotifications>
                      <processor type="xyz.GetPageEditorNotifications.YourClass,xyz" />
             </getPageEditorNotifications>
         </pipelines>
      </sitecore>
</configuration>

Your experience editor class will inherit the GetPageEditorNotificationsProcessor here is some sample code for the expriecne editor-

namespace xyz.GetPageEditorNotifications
 {
    public class YourClass : GetPageEditorNotificationsProcessor
      {
        public override void Process(GetPageEditorNotificationsArgs arguments)
          {
             Assert.ArgumentNotNull((object)arguments, "arguments");
             Item contextItem = arguments.ContextItem;
              // your code
          }
      }
  }

For Content editor, the code will look like this

namespace xyz.Warning
{
     public class YourClass
     {
        public void Process(GetContentEditorWarningsArgs args)
        {
            var item = args.Item;

            if (item == null)
                return;
            // Your Code

        }
    }
}

I guess this will help you.

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.