SharePoint: Redirection to a desired page after adding a New item to a list

Context 

One of the requirements that we frequently come across setting a return address of the NewForm.aspx page. That precisely means that if you are about to add a new item to a list, first you press the link "Add New Item" (or some other way) and a newform.aspx appears as a pop up. Upon filling the required fields and pressing Save you are redirected to the same list (All item view.) The problem arises if we don't to be redirected to this view rather to some other page. For that reason here is the trick.

Solution: 

The URL to newform.aspx consists of two query strings i.e. "RootFolder" and "Source". Let leave Rootfolder for now and focus "Source" Setting the Source with your desired URL will redirect the user to this specific desired page that has been point in the Source. Remember that source requires a URL encoding. you can encode your URL using the following link http://www.url-encode-decode.com/. So what I did is to place an anchor "h ref" html tag and set its id to "newEvent" and the used javascript to modify source url as follows:

function setNewEventLinkURL() {
    document.getElementById("newEvent").setAttribute("href", "../../Lists/TeamCalendar/NewForm.aspx?Source=" + window.location.pathname);
} 

The following example is little more specific to the requirement that I had. I was also required to send a query string. So in addition to setting source url you can also see how to fetch the query string out the current url using SPService and JQuery.

$('#btnConnect').click(function() {

var queryStringVals = $().SPServices.SPGetQueryString();
var userid = queryStringVals["userid"];
var username = queryStringVals["username"];
var Source = "http%3A%2F%2Fqa%2Emoss%2myfirm%2Fsites%2Fmy%2Dpage%2FPages%2FUserProfile%2Easpx%3Fuserid="+userid;
window.location.href = "/sites/Ladies-Lunch/Lists/User%20Profile%20Connections/ConfirmConnection.aspx?userid="+username+"&RootFolder=%2Fsites%2FLadies%2DLunch%2FLists%2FUser%20Profile%20Connections&ContentTypeId=0x010066B75FE6B089C14FADFCD05886C651DF&Source="+Source;

Reference:

http://techtrainingnotes.blogspot.de/2009/06/sharepoint-redirecting-to-page-after.html
Vaqar Hyder

E: vaqar.hyder3567@gmail.com

A:

Siebenbürgen Straße 2/1, Korntal-Münchingen, 70825, PK

Hire me on Freelancer.com

Comments

Popular posts from this blog

SPFx: Develop using SharePoint Framework without Installing all the dependecies.

SharePoint Online: Elevated Permissions....with love

Powershell: Filling up an Existing Excel Sheet with data from SQL Server