How to check if the url contains specific keyword in script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 06:46 AM
I want to check if (URL = <keyword>){ then do this} .. so we already have a script include? so i need add just one condition like this in the existing script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 06:52 AM
Check out the GlideURI class to investigate what's on the URI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 07:19 AM
Hi Chuck,
Thank you for the reply.
But i am not able to achieve it on my script. So can you just give me a piece of example code to check whether url has keyword ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2020 08:43 AM
Can you share what you have tried?
An example of using GlideURI to determine if a parameter is available and has a value is with the get() method.
var gURI = new GlideURI();
gURI.set('sysparm_query', 'priority=2^active=true' );
var fileString = gURI.get('sysparm_query');
gs.info(fileString);
If you want the entire URI, then use toString() on the gURI (see toString() in the linked doc above.) You can then use the standard JavaScript indexOf() method to determine if the URI contains your string somewhere.
var gURI = new GlideURI();
var myURI = gURI.toString();
if (myURI.indexOf('Chuck') != -1) {
gs.info('URI contains Chuck');
} else {
gs.info('URI does not contain Chuck');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 03:12 AM
If you are using client script only, then top.location.href can be used(this is to be used with onload client script)
