Friday, August 24, 2012

Open a SharePoint 2010 List Item dialog via a hyperlink

One of our users was looking for a way to consolidate several links that, when clicked, would open the standard dialog to create a new list item for the associated List located on her SharePoint 2010 site in the same way that the "Add new item" link functions.

The solution we ended up using was introduced by one of my Avanade compatriots in the UK, Phil Childs, and his write up can be found at the following URL: Open list item modal dialog (lightbox) with a hyperlink in SharePoint 2010

The code that highlights one of the many links we added to our Content Editor web part to make this solution work is presented as follows:

<script type="text/javascript">
var optionsCABRequest = {
url: "http://SiteUrl/_layouts/listform.aspx?PageType=8&ListId={GuidOfOurSharePointList}&RootFolder=",
    title: "Create a new CAB Request",
    allowMaximize: true,
    showClose: true,
    width: 735,
    height: 580,
    dialogReturnValueCallback: silentCallback};
function openNewCABRequestForm() {SP.UI.ModalDialog.showModalDialog(optionsCABRequest);}
function silentCallback(dialogResult, returnValue) {
}
function refreshCallback(dialogResult, returnValue) {
  SP.UI.Notify.addNotification('Operation Successful!');
  SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
</script>
<br/>
<div>Click <a href="javascript:openNewCABRequestForm()">here</a> to create a new CAB Request</div>

Our thanks definitely goes to Phil for creating and sharing this solution. It worked perfectly for what our user was trying to accomplish.  Thanks, Phil!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.