Approve multiple documents or list items in one operation with client side code

I got this request from Larry:

Good day A, Have a question. Is there an easy way to add to the SP 2010 ribbon an approve all button. I hate having to select each item and manually approve each one. I have found some script but they are deployed on central admin. I would like to a void that.

thanks

It’s not like i didn’t have anything to do, but he bought me a beer…

Here we go

This one uses the Client Object Model in SharePoint 2010 and is therefore usable in SharePoint 2010 only.

The code adds a custom button to the “Ribbon.Document” or “Ribbon.ListItem” that calls a script on the items selected using the in line checkbox.

Get the file “ApproveSelected.js” from here
Get jQuery from here

Put the files in a document library or in a folder created with SharePoint Designer. Ensure all users have read access to the location.

Insert a CEWP in the list view where you want this feature to be activated. Use the “Content Link” option in the “Edit web part” panel of the CEWP to link to the CEWP-code that you have put in a text file in the same location as the “ApproveSelected.js”.

Use this code:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="/test/Scripts/ApproveSelected/ApproveSelected.js"></script>
<script type="text/javascript">

var tabBtn = {btnLabel:'Approve selected',groupLabel:'Approve'};
var approvingItemsNotification = 'Approving files...';
var approvingItemsDoneNotification = '{0} items approved';
</script>

Change the path to the file “ApproveSelected.js” to match your local copy. If you prefer to use a local copy of jQuery, change that path to.

You may also change the variables if you want another text in the button or the notification messages.

It should look like this in the list view

Inactive
IMG

Active
IMG

NOTE
The button will disappear if the screen width is to narrow. The built in ribbon buttons will “shrink” to fit a narrow screen – this one will not.

Extras

This code uses a new “hack” to overcome the missing “list toolbar” when adding another webpart to the page. I’ll do a separate little article on that one.

Enjoy!
Alexander

Advertisement

9 Responses to “Approve multiple documents or list items in one operation with client side code”

  1. Larry Says:

    You rock! I owe you another beer. You can count on by pay day! Thanks A

    • Alexander Bautz Says:

      Hi,
      Glad you liked it :-)

      Alexander

  2. Michael Barrs Says:

    To check in multiple documents at once I use Harmon.ie ‘s ‘addin’ to Outlook. It allows you to select more than one document and check them in all from within Outlook. Very handy.

  3. Omegacron Says:

    Neat solution! Could you use the same basic script to trigger a workflow on all selected items?

    • Alexander Bautz Says:

      Hi,
      Yes, if the workflow is set to trigger on change you could modify this script to set the “trigger field” to the appropriate value.

      Alexander

  4. Pooja Says:

    Hi Alex,

    Thanks for the code. Is it possible to use this code for any other field?
    I have dropdown field with values Save as Draft, Submit, Approved and Rejected. So is it possible to change the dropdown value from Submit to Approved using ribbon button?

    Thanks in advance

    • Alexander Bautz Says:

      Hi,
      Yes this should be possible. You must change the function “checkAndUpdate” to achieve this. Look at the field “_ModerationStatus” – this is the one you should change for your “dropdown field”.

      Alexander

  5. advacomp Says:

    Awesome solution, thanks Alexander!!!! Now I don’t have to go into datasheet view anymore to approve multiple items!!!!

    Colin

    • Alexander Bautz Says:

      Glad you liked it :-)

      Alexander

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 )

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


Follow

Get every new post delivered to your Inbox.

Join 370 other followers