Automatically closing a SharePoint 2010 Edit form opened from a Reporting Services web part

SharePoint 2010 Edit and Display forms can be modified with InfoPath. This opportunity comes with a few new bugs, but the UI and functionality can be compelling.

It takes a snippet of Javascript, but a Reporting Services web part can open one of these new list or library Edit forms with a GoToURL action. On submit or close, however, the form will either close to the list it came from or it will close to a “This form has been closed” window. It matters not whether the form is opened in the same window (target = _self) or in a new window (target = _blank). Nor does it matter if the form is set to close on submit. Neither option closes the form back to the page that launched it, and both interrupt the user flow with additional clicks to close the form window.

If adding code to the form page is a non-starter, one workaround is to close the form to another page where script can be added. This is done using the &Source part of the URL string that opens the window.

Step 1 – Create a simple SharePoint ASPX page. This can be done using SharePoint Designer 2007 (adds the basic ASPX lingo automatically), Visual Studio, NotePad++, or etc. That should result in something like the following tags:

<%@ Page Language="C#" %>
<html dir="ltr">
	<head runat="server">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
			<title>Untitled 1</title>
		<meta name="Microsoft Theme" content="Providence 1011, default">
	</head>
	<body>
		<form id="form1" runat="server"></form>
	</body>
</html>

Step 2 – Add Javascript to the section that has the page close itself on open. Calling open() first, bypass a potential window close confirmation dialog box.

<script language="javascript" type="text/javascript">
    window.open("", "_self");
    window.close();
</script>

Step 3 – Save the page as “Close.aspx” and upload it to a Document Library on the SharePoint site that is easy to access.

Step 4– Set the &Source parameter in the Report Builder web part’s URL expression to the url of the Close.aspx page. This is the URL that InfoPath will return the user to after the browser form is closed. The example below links to an Edit form in an External List that opens a specific item based on its BDCIdentity ID:

="javascript:void(window.open('http://sitecollection/site/Lists/ListName/Item/editifs.aspx?ID=" + Fields!BDCIdentityKey.Value + "&Source=http://sitecollection/site/Pages/Close.aspx','_blank'))"

The resulting link should open the Edit form in a new window, and when the form is saved or closed, it goes to the close.aspx page that closes instantly, leaving the user back at the window of origin.

References:

  • http://johnliu.net/blog/2011/6/17/infopath-2010-close-the-browser-window.html
  • Advertisements

    One thought on “Automatically closing a SharePoint 2010 Edit form opened from a Reporting Services web part

    1. Just a quick update: This works in IE 8, but Firefox will not allow me to close windows that I didn’t open via script. I’ve tried the source in this post and it was a no-go. I’ll just add a message to the page which tells the user she can close the page.

    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 )

    Google+ photo

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

    Connecting to %s