Prexens team dev' corner

How-to: Replace ‘Submit for approval’ custom quick access button

Goal of this post

The goal of this post is to guide you through the different steps for replacing the ‘Submit for Approval’ quick access button in a WCM environment.


Problematic overview

‘Submit for Approval’ is a native button which aims at firing a ‘Parallel Approval’ workflow when Publishing features are activated  in a WCM web site:

 

Native Approval button

 

When deploying a custom approval workflow, you’ll probably need to overwrite the logic of this button to start your custom workflow correctly.
You would also be able to customize the icon and the text of your custom button to achieve something like this:

 

Custom approval button

 

Write a custom class CustomSubmitForApproval

 

1. Set pre-requisites:

 

  • First, add those tworeferences : Microsoft.SharePoint, Microsoft.SharePoint.Publishing
  • Create a public sealed class that inherits from:
    Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction
  • Add a constant used as argument of post back events:
private const string PostBackEventArg = "submitForApproval";

 

2. Add a constructor and customize your custom quick access button:

public CustomSubmitForApprovalButton()
            : base()
{
      this.DisplayText = "Custom Submit for Approval";
      this.ImageUrl = "/_layouts/images/workflows.gif";
}

 

3. Override NavigateUrl property and fire post back events:

public override string NavigateUrl
{
     get
     {
          return String.Format("javascript:{0}", Page.ClientScript.GetPostBackEventReference(
this, CustomSubmitForApprovalButton.PostBackEventArg));
     }
}

 

4. Override RaisePostBackEvent method, and implement your redirection logic

 

In our case, we force the page check in and we redirect toward check-in page:

public override void RaisePostBackEvent(string eventArgument)
{
    try
    {
        if (eventArgument == CustomSubmitForApprovalButton.PostBackEventArg)
        {

            SPFile myFile = SPContext.Current.File;

            // Auto checkin page before redirecting to 'Publish Major Version'
            if (myFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
            {
                myFile.CheckIn("Default comment", SPCheckinType.MinorCheckIn);
            }

            string redirectUrl = String.Format(
                    "{0}_layouts/Checkin.aspx?FileName={1}&Publish=true&List={2}&Source={3}",
                    SPContext.Current.Web.ServerRelativeUrl,
                    SPContext.Current.ListItemServerRelativeUrl,
                    Convert.ToString(SPContext.Current.List.ID),
                    Page.Request.Url.OriginalString);

            SPUtility.Redirect(redirectUrl, SPRedirectFlags.Default, HttpContext.Current);
        }

    }
    catch (Exception ex)
    {
        ShowError(ex, new ConsoleError(ex.Message));
    }
}

 

You can override some properties to control what is the minimum level of permission required to access the feature, and what are the states causing your button to appear in the page editing toolbar. In samples below, users have to be granted the permission of adding items and page has to be a publishing page waiting for approval.

 

 

5. Override SPBasePermissions UserRights property

public override SPBasePermissions UserRights
{
    get { return SPBasePermissions.AddListItems; }
}
6. Override AuthoringStates RequiredStates property
public override AuthoringStates RequiredStates
{
    get
    {
        return AuthoringStates.IsPublishingPageTrue |
            AuthoringStates.SaveConflictExistsFalse |
            AuthoringStates.IsMajorVersionFalse |
            AuthoringStates.IsApprovalWorkflowConfiguredTrue |
            AuthoringStates.InEditModeFalse |
            AuthoringStates.IsApprovalWorkflowRunningFalse;
    }
}


 

Overwrite CustomQuickAccess.xml file in master pages gallery


When your custom class is compiled and deployed on your SharePoint server, you will have to overwrite CustomQuickAccess.xml located into MOSS master pages gallery.


In a live scenario, we recommend to deploy this file through activation event of a custom feature. Simply make sure not to override an already existing file.
In our sample scenario, we are going to edit this file directly from SharePoint Designer :


1. Open CustomQuickAccess.xml from /_catalogs/masterpage/Editing Menu


 

2. Add a reference to our custom class (mind to adjust assembly reference with your own assembly qualified name):

<references>
 <reference TagPrefix="Prexens"
      assembly="Prexens.SharePoint.CustomQuickAccessButton, 
Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"
namespace="Prexens.SharePoint.CustomQuickAccessButton" /> </references>

3. Add a ConsoleNode that override native qaPublish Node ID:


<structure>
 <ConsoleNode 
Sequence="65"
  ConfigMenu="Replace"
  Action="Prexens:CustomSubmitForApprovalButton"
  ID="CustomQuickAccessButton_SubmitForApproval"
  ChangedNodeID="qaPublish" />
</structure>

 

4. Add two ConsoleNode that remove native Approve and Decline buttons (those two feature should probably be inconsistent with your custom publishing workflow):

<ConsoleNode ConfigMenu="Delete" ChangedNodeID="qaWorkflowDecline" />
<ConsoleNode ConfigMenu="Delete" ChangedNodeID="qaWorkflowApprove" />


5. Save, publish, and approve this file in master pages gallery


Comments

Jens Gyldenkærne Clausen says :

Could this method be used to replace or override the standard &quot;publish&quot; button with a workflow asking the user for a check-in comment before publishing - and preferably also a link to discard check out.

The object would be to avoid dummy check-in&#39;s without any changes - and to make the version history much more useful than now (where tons of versions lie side by side with no comments and few or no changes between most of them).

6/26/2009 5:57 PM

Hello world August says :

Thank you for your information,

But I wanna replace ‘Approve’ and &quot;Publish&quot; quick access button in page editing toolbar...

Could you please advise me?

6/30/2009 6:06 AM

Sébastien AMBROGIO says :

&quot;Publish&quot; standard button replaces the standard &quot;Submit for approval&quot; button when the standard approval workflow isn&#39;t associated and configured. Their ids are the same : qaPublish

Jens Gyldenkærne : yes you can use this method to override the standard &quot;qaPublish&quot; button.

Hello world August : you should try to override the qaWorkflowApprove and the qaPublish buttons by creating custom classes and adding console nodes in your CustomQuickAccess.xml file to make them replacing the standard controls.

Sorry for the late answer.

Best regards,
Sébastien AMBROGIO

7/29/2009 6:36 PM

Matthijs Wensveen says :

I get an error saying &quot;The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type.&quot;
Any ideas how to fix this?

2/18/2010 3:56 PM

Sébastien AMBROGIO says :

Matthijs, I didn&#39;t encountered this error. Could you please double-check your CustomQuickAccess.xml file ? If the XML syntax is correct, check the class constructor name and the Action attribute of the ConsoleNode.

2/22/2010 10:37 AM

Add a new comment

Please  [ Sign in ] to add a new comment
Categories
Links
  Prexens Web Site
  Charting for SharePoint
  Charting for SharePoint (Codeplex)
  Charting for SharePoint Starter kit

Microsoft Certified Partner