- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2014 12:55 PM
On a front page I want to be able to have several links to one record producer and pass some of the data in the url so some of the fields can be pre-filled. I've done this with incidents before with the sysparm_query by adding sysparm_query=priority=1^incident_state=3 to the url
But I can't seem to get it to work with record producers. Keep in mind that I'm using custom variables.
Is this possible?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2014 01:24 AM
Use an onLoad Catalog Client Script like the below:
function onLoad() {
var cmdb_ci = getParmVal('sysparm_cmdb_ci');
if (cmdb_ci) {
g_form.setValue('cmdb_ci', cmdb_ci);
}
}
function getParmVal(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 unescape(results[1]);
}
}
and you can pass in like:
var params = 'sysparm_cmdb_ci=' + current.sys_id;
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=c60ea0806f159500d9c316ff8d3ee400';
action.setRedirectURL(url + '&' + params);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2014 05:32 AM
Thank you so much, this worked beautifully!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2014 06:23 AM
Thanks very much for this helpful code, Andrew. Just to say in the getParmVal() code, in the context I needed (a link to a pre-populated record producer from a CMS page), it was necessary to replace window.location.href with document.referrer, so
var results = regex.exec( window.location.href ); //old
var results = regex.exec( document.referrer ); //new
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2016 04:26 AM
I prefer using the way proposed in: Parse URL Parameters in a Client Script - ServiceNow Guru
Is there a reason you are implementing your own parsing function?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2016 06:49 AM
For anyone trying to do what this question is asking, try what Julian is suggesting unless you want to practice your coding chops. mark.stanger this is the second time I have used your code to perform a function I was looking to do. Thank you very much for writing and explaining such good stuff!
julianhoch great call!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2016 09:19 AM
Hello Andrew and thanks for the script, it works very well, however if I am passing a parameter that is made of a paragraph with multiple lines (example Description) the copied values are transferred into the new form as one single line with no line jumps