Wednesday, October 26, 2016

JavaScript Navigation tricks in SharePoint forms

1. Navigate from NewForm.aspx to DisplayForm.aspx in SharePoint after clicking Save button.


Under PreSaveAction function add the below steps

var URL = location.pathname.replace('NewForm.aspx','DispForm.aspx');
if(GetUrlKeyValue('IsDlg')==='1'){
URL+="?IsDlg=1";
}
$("#aspnetForm").attr('action',location.pathname+"?Source="+URL);
return true;





2. Navigate from DisplayForm.aspx in one list to NewForm.aspx in another list with few of the fields populated.


HTML:
<span  style="font-size:x-large">To continue to phase 3, please <a href="#" target="_blank" id="Phase3Link">click here</a>.</span>

JavaScript:
$(document).ready(function(){
var requestID = $("#RequestID").text();

var phase3NewFormURL = "https://accobrands.sharepoint.com/sites/Departments/USOpsSC/OracleISRT/Lists/IMCRP3/P3NewForm.aspx?ReqId=" + requestID + "&Source=https://accobrands.sharepoint.com/sites/Departments/USOpsSC/OracleISRT/Pages/MyReqs.aspx";

$("#Phase3Link").attr("href", phase3NewFormURL);
//SetItemNumber(requestID, itemNumberTCell);

});


In P3NewForm.aspx

$(document).ready(function(){
//$("#imStatus").hide();
GetCurrentUserName(false, false);
/* Parse query string and set Request ID */
var requestIDQueryString = GetUrlKeyValue("ReqId");
var requestIDField = $("input[title='Request ID']");
requestIDField.val(requestIDQueryString);

requestIDField.prop("readonly", "true");
});


No comments:

Post a Comment