- 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:52 AM
function onLoad() {
var url = getParameterValue('url');
var blockReason = getParameterValue('reason');
var reasonCode = getParameterValue('reasoncode');
var action = getParameterValue('action');
var urlCategory = getParameterValue('cat');
var desc = 'Block Reason: ' + blockReason + '\n Reason Code: ' + reasonCode + '\n Action: ' + action + '\n URL Category: ' + urlCategory;
var shortDesc = 'url = ' + url;
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]);
}
}
}try the above code.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 04:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 05:36 AM
can you share the URL you try.
Thanks
dgarad
- 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 11:24 PM - edited 05-21-2024 11:26 PM
@dgarad Thank you so much! This works for me. The URL I was using had '%3Furl%3D' instead of '&url='. That's why it was not getting decomposed.
Also, on a side note, 'unescape()' is deprecated. Instead, we can use 'decodeURIComponent()'.
