Automatically create new version for Lock & Edit without workflow

Sitecore will create a new version on Lock and Edit if the item is tied to a workflow. For our case, version has to be created even without using workflow.

As mentioned by Dylan here, we can override the default behavior of Sitecore. Here we overridden the “Checkout” command which is executed on Lock & Edit.

Added a setting called EnableAddVersionWithoutWorkflow as a flag to enable this feature. If it is true, it will add a version and lock the new version for the user.

Note: By default, only a non-admin user will see the lock and edit button for an item. 
            if (!item.Locking.IsLocked())
            {
                Log.Audit(this, “Start editing: {0}”, new string[]
                {
                    AuditFormatter.FormatItem(item)
                });
                if (Context.User.IsAdministrator)
                {
                    item.Locking.Lock();
                }
                else if (bool.Parse(Settings.GetSetting(“EnableAddVersionWithoutWorkflow”, “false”)))
                {
                    Error.AssertObject(item, “item”);
                    if (StandardValuesManager.IsStandardValuesHolder(item))
                    {
                        this.Lock(item);
                    }
                    Item item2 = item.Versions.AddVersion();
                    if (item2 != null)
                    {
                        item = this.Lock(item2);
                    }
                }
                else
                {
                    item = Context.Workflow.StartEditing(item);
                }
                Context.ClientPage.SendMessage(this, string.Concat(new object[]
                {
                    “item:startediting(id=”,
                    item.ID,
                    “,version=”,
                    item.Version,
                    “,language=”,
                    item.Language,
                    “)”
                }));

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this: