SharePoint Events

  5/13/2013 - Conference: SharePoint Summit 2013
  5/21/2013 - Webcast: SharePoint 2013 and ECM: Content Migration and Storage
  5/22/2013 - Webcast: Managing CAD in SharePoint
  5/23/2013 - Webcast: SharePoint Document Automation and E-Forms for Financial Services
  5/24/2013 - Webcast: What's New in Search for SharePoint 2013

 SharePoint Videos

  Why SharePoint 2013
  SharePoint 2013 Launch
  SharePoint 2013 Migration and Governance
  SharePoint 2013 and Enterprise Content Management
  Top Benefits of SharePoint 2013
  What's New in Business Intelligence in Office and SharePoint 2013
  SharePoint and Office 2013 Integration
  SharePoint 2013 Infrastructure Preview
  SharePoint, Lync, and, Exchange in the Cloud with Office 365
  Advanced Reporting in SharePoint with Microsoft Power View

 Archives

Opening SharePoint Links in a new windowUse SHIFT+ENTER to open the menu (new window).
Mail Enabled Lists vs. The Missing Windows 2008 POP3/IMAP Server Use SHIFT+ENTER to open the menu (new window).
7 Tools for SharePoint DevelopersUse SHIFT+ENTER to open the menu (new window).
Public Facing Masterpage TechniquesUse SHIFT+ENTER to open the menu (new window).
How to Quickly Deploy and Activate a Timer Service to Your Site CollectionUse SHIFT+ENTER to open the menu (new window).
Custom SharePoint Master Page Feature with WSP BuilderUse SHIFT+ENTER to open the menu (new window).
Date Math with InfoPathUse SHIFT+ENTER to open the menu (new window).
Enterprise Search Tricks and Tips Part 1Use SHIFT+ENTER to open the menu (new window).
Populating Word Documents With SharePoint Data. Try The DIP!Use SHIFT+ENTER to open the menu (new window).
Programmatic Deep Dive into Blank SharePoint Lookup ColumnsUse SHIFT+ENTER to open the menu (new window).
1 - 10 Next
Launching Quick Actions in a Modal Dialog

By: Omar Stewart

 

Recently a co-worker asked if he could create a quick action from SharePoint designer, that launches a modal window and passes in a list item ID. This should really just be a checkbox in SharePoint designer but since its not, we can leverage SharePoint's beautiful and simple UI Dialog framework.

 

For our scenario, we have a list of projects we would like to allow employees to quickly add comments to. There are tons of ways to do this, but we want users to be able to do so without leaving the page.

 

We'll create a simple Projects list to house our Project Content Type.

 

All the content type will have is "Project Title, Project Description, and Project Leader"

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog 

 

We'll also create a project comment content type with a Comment Author, Project Comment, and Associated Article. For the Associated Article Column, configure it to be a lookup column, and have it point to the Projects List and grab the project title.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Then we'll just create a list to display the User and Project Comment.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog 

 

Now this is where it gets really fun.

 

We'll browse to our Projects list and edit the page.

 

Click on the Projects List Web Part, then click Web Part Tools: Options on the Ribbon.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Now click "Insert Related List" and select the Comments list from the drop down.

 

We can now filter our comments view below by clicking on the select icon in the projects list for any project.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Now we want users to be able to add a comment without leaving the page.

 

Open SharePoint designer and select your Comments list.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

In the Forms section, click New to create a new Form. Title the form "AddComment" and make sure its set to use the "Project Comment" Content Type. We'll also leave default-form  unchecked.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

 

Click to edit the form, then click Advanced mode so we can make some changes to the code-behind.

 

Scroll down to the bottom of the page source and add some comments to declare our script section.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

We'll first add our JQuery reference. Then we'll add our actual script:

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

<!-- Setting the default value of the associated project for our article comments -->

 

<!-- Reference JQuery -->

<script type="text/javascript" src="/ScriptLibrary/jquery-1.5.min.js"></script>

 

<script type="text/javascript">

 

$(function(){

 

//Get our Associated Project DropDown Field By its Title.

//SharePoint adds a title with the column name to form fields.

var AssociatedProjectDropDown = $('select[title=AssociatedProject]');

 

//Get the value of the associated project.

var AssociatedProject = getParameterByName('AssociatedProjectId');

 

//Now we'll set the value of the drop down based on our value

AssociatedProjectDropDown.val(AssociatedProject);

 

//Function to pull values from query string

function getParameterByName( name )

{

  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

  var regexS = "[\\?&]"+name+"=([^&#]*)";

  var regex = new RegExp( regexS );

  var results = regex.exec( window.location.href );

  if( results == null )

    return "";

  else

    return decodeURIComponent(results[1].replace(/\+/g, " "));

}

 

});

 

</script>

<!-- Setting the default value of the associated project for our article comments -->

 

 

You're done with editing the form. Save and navigate to the "Projects" List.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Now all we have to do is create our custom action.

 

While in the Projects Library Settings page, click Custom Action, then click List Item Menu.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Give the action a title of "Comment on this Project"

 

Then change the action type to "Navigate to URL".

 

For the Url, we'll throw in our AssociatedProjectID in part of the SP.UI Framework call.

 

Our full url should be

"javascript:var options={url:'/sites/projects/Lists/Comments/AddComment.aspx?AssociatedProjectId={ItemId}',title:'Leave Comment'};SP.UI.ModalDialog.showModalDialog(options);"

*without quotes

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Now just browse to your page, click the list item drop down, and you should see your Leave Comment action.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Now users can just leave a comment. Once you enter the comment and click save, the comment will be posted, and the new dialog window is automatically closed. Refresh your page and you should see the new comment added to your page.

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

The_SharePoint_Blog_Launching_Quick_Actions_in_a_Modal_Dialog

 

Hope this helps!

 

By: Omar Stewart

        

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Your Name *


e-mail address *


Website (optional)


Comment *


Attachments

 Subscribe

  GigWerks RSS  Gig Werks Mailing List 

 Contact Us

 Connect

 Resources

  On Demand SharePoint Webcast Recordings
  Upcoming Webinars
  SharePoint Resources
  Business Intelligence Resources
  Gig Werks Website



©2009 Gig Werks. All rights reserved. Privacy Policy