Timeline for getURLParameter(ID)
Current License: CC BY-SA 4.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 28, 2020 at 15:10 | comment | added | akapital | entered this in console and returns 20, 21, 22, etc. Appears to be pulling a different ID than url: function getUrlParameter(name) {name = name.replace(/[[]/, '\[').replace(/[]]/, '\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '8' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }function populateNewForm() {document.getElementById("Project_x0020_Name_c9c83d51-e59d-4fc8-b811-d8eee5fd6818_$LookupField").value = getUrlParameter('ID'); }_spBodyOnLoadFunctionNames.push("populateNewForm") | |
May 27, 2020 at 21:32 | comment | added | akapital | The fact that the null value is populating tells me that though the ID is there in the URL it is not getting found and/or poulated. Perhaps it is a timing issue and I need to add/use the window.onload or $(document).ready function? | |
May 27, 2020 at 21:17 | comment | added | akapital | At the very least I am able to populate a default value when specified. So for example if I replace null ?'' with null ? '8' it succesfully populates the Document Set that corresponds with ID=8 | |
May 27, 2020 at 21:14 | comment | added | akapital | thank you so much for the code, I am sure it would work were I not using a SharePoint document set and having to pull the Document Set ID from the ?Source= section of a very long and encoded url and then populate that ID in a new form. Based on further research it appears that perhaps ID is reserved for another value on the newform.aspx page and therefore I am unable to populate. Further, I am certain that this can be done but it is subject to the constrainsts and idiosyncrasies of working with SharePoint. Thanks again. I will follow up soon if I find anything useful.@Warwick W | |
May 27, 2020 at 21:04 | comment | added | akapital | Thanks and added populate newform function at end but didnt work: getUrlParameter(name) { name = name.replace(/[[]/, '\[').replace(/[]]/, '\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '8' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; const itemID = getUrlParameter("ID"); alert(itemID); }function populateNewForm() {document.getElementById("Project_x0020_Name_c9c83d51-e59d-4fc8-b811-d8eee5fd6818_$LookupField").value = getUrlParameter("ID");} _spBodyOnLoadFunctionNames.push("populateNewForm") | |
May 27, 2020 at 0:05 | comment | added | Warwick W |
paste the code below into your site and I'm sure it will work, and go from there function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; const itemID = getUrlParameter("ID"); alert(itemID);
|
|
May 26, 2020 at 12:44 | comment | added | akapital | thanks for the responses and result is populating the default value which tells me that code is not successfully pulling the ID field. I wonder whether since the ID is nested in the ?Source=https.... section of the URL if I need to use a different function, maybe search string instead of url parameter? Does url parameter search the full url? Also do I need to replace name in above code with "ID" (single quotes or double quotes?) Thank you. @Warwick W | |
May 24, 2020 at 23:44 | history | edited | Warwick W | CC BY-SA 4.0 |
updates with code
|
May 24, 2020 at 23:42 | comment | added | Warwick W |
I use this function almost everyday and never has an issues function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); };
|
|
May 24, 2020 at 23:42 | comment | added | Warwick W | comment out the field update for now and just write the output of the function to the console.log(getUrlParameter(ID)); - get that working and then do the second part to update list | |
May 24, 2020 at 23:39 | comment | added | Warwick W | what error are you getting/seeing? | |
May 22, 2020 at 20:17 | comment | added | akapital | Tried this but did not work, any ideas: <script type="text/javascript"> function getUrlParameter(ID) {ID = ID.replace(/[[]/,"\\[").replace(/[]]/,"\\]"); var regexS = "[\\?&]"+ID+"([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results == null ) return "8"; else return decodeURI(results[1]); }function populateNewForm(){ //Populate SPListForm document.getElementById("Project_x0020_Name_c9c83d51-e59d-4fc8-b811-d8eee5fd6818_$LookupField").value = getUrlParameter('ID'); }_spBodyOnLoadFunctionNames.push("populateNewForm") </script> | |
May 22, 2020 at 15:47 | comment | added | akapital | I was able to find many related posts which decode the url: stackoverflow.com/questions/7731778/… stackoverflow.com/questions/19491336/… stackoverflow.com/questions/25161246/… but don't know js well enough to marry with the populate new form script that was my starting point. @Warwick W | |
May 22, 2020 at 13:39 | comment | added | akapital | Warwick, thank you for your response, so I will try to decode the URL before passing through the function and update with the result. | |
May 22, 2020 at 0:51 | history | answered | Warwick W | CC BY-SA 4.0 |