Redirecting SPD NewForm.aspx to other pages with the Current Item ID as Query String

Business Need

We have a site request SharePoint List. Users will raise request using this list to get a new SharePoint WIKI article. Once the user press the Save button in the OOB SharePoint Designer form (which we customized using SPD 2010), it should redirect to one Status Page and wait there till the workflow creates the new site and configure the permission based on the meta data submitted by the requestor.

Once the workflow is completed we have to check the status of the workflow. If the status of the workflow is “Success” then we have to redirect the page to the newly created site. If the status is “Failed” then we have to show an alert message.


Basically in SPD forms once the data is submitted, the page will be redirected to the page where you came from.

The problem here is to identify the ID of the newly created item and check the workflow status using that ID since the ID for the new item is unknown before the item has been created


To solve this we have to follow the below steps explained in the below article :


First Open the customized New / Edit form in SPD 2010 and override the SharePoint default save buttons with the HTML input buttons

<input type=”button” value=”Save” name=”btnSave” onclick=”javascript: {ddwrt:GenFireServerEvent(‘__commit;__redirect={/Sites/<Site Name>/<Library Name>/GetLastID.aspx?RedirectURL=/Sites/<Site Name>/<Library Name>/WIKIStatus.aspx}’)}” />

Note: Replace the Site Name and Library Name with your details

Now create an intermediate page (GetLastID.aspx) and paste the below code then upload this in any of your document library of your site.  All this page does is find the most recent item in the list which was created by the current user and redirect to WIKIStatus.aspx with the ID on the Query String (ParaID).

<%@ Page Language=”C#” inherits=”Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

<%@ Register Tagprefix=”Utilities” Namespace=”Microsoft.SharePoint.Utilities” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

<%@ Import Namespace=”Microsoft.SharePoint” %>

<%@ Register Tagprefix=”WebPartPages” Namespace=”Microsoft.SharePoint.WebPartPages” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>


<head runat=”server”>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>



<form id=”form1″ runat=”server”>

<WebPartPages:DataFormWebPart runat=”server” IsIncluded=”True” FrameType=”None” NoDefaultStyle=”TRUE” ViewFlag=”0″ Title=”Events” __markuptype=”vsattributemarkup” __WebPartId=”{020AF483-2135-4D37-B6C7-CD6A6FD6AF5D}” id=”g_a8a4d070_e7c0_4105_a113_acff9dea3328″ pagesize=”1″ __AllowXSLTEditing=”true” WebPart=”true” Height=”” Width=””>


<SharePoint:SPDataSource runat=”server” DataSourceMode=”List” UseInternalName=”true” selectcommand=”<View><Query><Where><Eq><FieldRef Name=&quot;Author&quot;/><Value Type=&quot;Integer&quot;><UserID/></Value></Eq></Where><OrderBy><FieldRef Name=&quot;Created_x0020_Date&quot; Ascending=&quot;FALSE&quot;/></OrderBy></Query></View>” id=”dataformwebpart2″>


<WebPartPages:DataFormParameter Name=”ListName” ParameterKey=”ListName” PropertyName=”ParameterValues” DefaultValue=”Test List”/>





<ParameterBinding Name=”UserID” Location=”CAMLVariable” DefaultValue=”CurrentUserName”/>

<ParameterBinding Name=”RedirectURL” Location=”QueryString(RedirectURL)” DefaultValue=””/>


<datafields>@Title,Title;@Start_x0020_Time,Start Time;@End_x0020_Time,End Time;@ZIP_x0020_Code,ZIP Code;@Amount,Amount;@Nominee,Nominee;@ID,ID;@ContentType,Content Type;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</datafields>


<xsl:stylesheet xmlns:x=”; xmlns:d=”; version=”1.0″ exclude-result-prefixes=”xsl msxsl ddwrt” xmlns:ddwrt=”; xmlns:asp=”; xmlns:__designer=”; xmlns:xsl=”; xmlns:msxsl=”urn:schemas-microsoft-com:xslt” xmlns:SharePoint=”Microsoft.SharePoint.WebControls” xmlns:ddwrt2=”urn:frontpage:internal”>

<xsl:output method=”html” indent=”no”/>

<xsl:param name=”UserID”>CurrentUserName</xsl:param>

<xsl:param name=”RedirectURL” />

<xsl:template match=”/” xmlns:x=”; xmlns:d=”; xmlns:asp=”; xmlns:__designer=”; xmlns:SharePoint=”Microsoft.SharePoint.WebControls”>

<xsl:call-template name=”dvt_1″/>


<xsl:template name=”dvt_1″>

<xsl:variable name=”Rows” select=”/dsQueryResponse/Rows/Row”/>

<xsl:for-each select=”$Rows”>

<xsl:call-template name=”dvt_1.rowview” />



<xsl:template name=”dvt_1.rowview”>

document.location.href = '' +

"?ParaID=" + '';








Note: Replace “Test List” with your list name

Now create a new page and name it as “WIKIStatus” and add the below script in a CEWP. All this CEWP page does is check the status of the workflow for the Item Id received from the Query String.  If the value of the status column is “Success” then it will redirect the page to the newly created site (which was updated by the workflow behind the scene). If the status is “Failed”, then it will show an alert message.

ExecuteOrDelayUntilScriptLoaded(runCode, “sp.js”);

var itemId = querySt(“ParaID”);   // Query String

var targetListItem;

function runCode()


var clientContext = new SP.ClientContext();

var targetList = clientContext.get_web().get_lists().getByTitle(‘Test List’); // Change the List Name here

targetListItem = targetList.getItemById(itemId);

clientContext.load(targetListItem, ‘Status’, ‘SiteURL’); // Select the column names here

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));


function onQuerySucceeded()


if(targetListItem.get_item(‘Status’) != “Completed” || targetListItem.get_item(‘Status’) != “Failed” )




if(targetListItem.get_item(‘Status’) == “Completed”)


document.location.href = targetListItem.get_item(‘SiteURL’);


if(targetListItem.get_item(‘Status’) == “Failed”)


alert(“Please contact the administrator.”);



function onQueryFailed(sender, args)


// alert(‘Request failed. \nError: ‘ + args.get_message() + ‘\nStackTrace: ‘ + args.get_stackTrace());

alert(‘Request failed. \n Contact Admin ‘);


function querySt(Key)


var url = window.location.href;

KeysValues = url.split(/[\?&]+/);

for (i = 0; i


1)      Replace “Test List” with your list name

2)      “Status” and “SiteURL” are the two columns iam refereing from my site request list

That’s it you are done 🙂 . Thank you Marc for the idea you have explained in your article.