Last active
September 24, 2015 02:48
-
-
Save kitmenke/9948277 to your computer and use it in GitHub Desktop.
Auto-populate a SharePoint field using a URL Parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="/kitsite/Files/jquery-1.11.0.min.js"></script> | |
<script src="/kitsite/Files/sputility.min.js"></script> | |
<script> | |
// url parsing from http://stackoverflow.com/a/2880929/98933 | |
var urlParams; | |
(window.onpopstate = function () { | |
var match, | |
pl = /\+/g, // Regex for replacing addition symbol with a space | |
search = /([^&=]+)=?([^&]*)/g, | |
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, | |
query = window.location.search; | |
// fix for sharepoint 2013 URLs which use the hash | |
if (query === '') { | |
query = window.location.hash.substring(window.location.hash.indexOf('?')); | |
} | |
query = query.substring(1); | |
urlParams = {}; | |
while (match = search.exec(query)) | |
urlParams[decode(match[1])] = decode(match[2]); | |
})(); | |
// wait for the window to load | |
$(window).load(function () { | |
try { | |
var urlValue = urlParams['projectID']; | |
SPUtility.GetSPField('Project ID').SetValue(urlValue).MakeReadOnly(); | |
} catch (ex) { | |
alert(ex.toString()); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment