function onLoad() { //Use the 'getURLParam' function below to get the parameter values from the URL var id = getURLParam('sysparm_id'); var description = getParmVal('sysparm_description'); if(id){ g_form.setValue('id',id); } if(description){ g_form.setValue('my_description_variable',description); } } For Native View function getURLParam(name){ var url = document.URL.parseQuery(); if(url[name]){ return decodeURI(url[name]); } else{ return; } } For ServicePortal function getURLParam(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(top.location); if (results == null) { return ""; } else { return unescape(results[1]); } }
How to get Parameters from URL in a Client Script ServiceNow
admin Changed status to publish December 19, 2023