- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 03:08 AM - edited ‎05-21-2024 03:12 AM
Hello, I am trying to decompose a URL and get its parameters. I was able to get the URL using catalog client script. In that used URL(top.location).
Also, I was able to get the rest of the required parameters. But there is one parameter 'url' in that URL. I am getting null value for it even though it is present in the URL. How to get that parameter value?
here is the sample URL: https://instance_name.service-now.com/sp?id=sc_cat_item&sys_id=sample_sys_id&sysparm_category=category_sys_id%3Furl%3Dhttp:%2F%2Fsample_url%2Fhttp-post%2F&referer=&reason=abc&reasoncode=xyz
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 05:48 AM
Hi @ArpitaVK
I have tried the URL and code it's working for me.
https://instance_name.service-now.com/sp?id=sc_cat_item&sys_id=bd0c5e6a97040210b958f84de053af8c&sysparm_category=e15706fc0a0a0aa7007fc21e1ab70c2f&url=http:%2F%2Fsample_url%2Fhttp-post%2F&referer=&reason=abc&reasoncode=xyz
function onLoad() {
//Type appropriate comment here, and begin script below
var url = getParameterValue('url');
//alert(url);
var blockReason = getParameterValue('reason');
var reasonCode = getParameterValue('reasoncode');
var action = getParameterValue('action');
var urlCategory = getParameterValue('sysparm_category');
var desc = 'Block Reason: ' + blockReason + '\n Reason Code: ' + reasonCode + '\n Action: ' + action + '\n URL Category: ' + urlCategory;
var shortDesc = 'url = ' + url;
alert("desc:"+"\n"+desc +"\n"+"shortDesc :"+shortDesc);
//g_form.setValue('short_description', shortDesc);
// g_form.setValue('description', desc);
}
function getParameterValue(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]);
}
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 03:36 AM
Hi @ArpitaVK
create onLoad client script. try the below code.
var url= getParameterValue('url');
function getParameterValue(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]);
}
}
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 03:43 AM
Hi @dgarad
Using above code I am not getting any parameter now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 03:44 AM
can you share your code.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 03:48 AM
