Lots of great posts on using the getURLParameter(ID) to populate a lookup column in a NewForm.aspx when coming from a list view web part on another page. Here is my problem, the source url that I am querying does not have an explicit "ID=6" but instead since I am coming from a document set home page looks like this:"...%2FSharePoint%2FProject%2520Document%2520Set%2FForms%2FProject%2Fdocsethomepage%2Easpx%3FID%3D6..."
So the part that I am trying to parse or get the url parameter is "FID%D6"
instead of simply ID=6
.
I tried using this code which I got from a similar post (apologies for being unable to give credit to original poster) but did not successfully populate the ID. Was only able to populate the Null result:
<script type="text/javascript">
// this fetches the parameter from the current url
// CASE SENSITIVE
function getUrlParameter( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null ) return "";
else return results[1];
}
function populateNewForm()
{
//Populate your field
//to know the element id of your field you use the IE dev tools
document.getElementById("Project_x0020_Name_c9c83d51-e59d-4fc8-b811-d8eee5fd6818_$LookupField").value = getUrlParameter("ID");
}
_spBodyOnLoadFunctionNames.push("populateNewForm")
</script>
Any ideas on edits to use this code to parse this type of URL and/or any other existing solutions that anyone is aware of? Here is my attempt to edit the code and decode the encoded url but it is not working:
// this fetches the parameter from the current url // CASE SENSITIVE var UrlParams = document.URL.split("?")[1].split("&"); var GetUrlParam = function ('ID') { for (var i = 0; i