We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Get Hostname from any url in server side.

ShantanuB
Tera Contributor

Hi All,

 

I have one requirement in the email inbound action script, I want to get hostname from the url as below.

In the email, as below url will be provided.

How we can achieve this.

 

                                                 Expected HostName

https://www.google.com           www.google.com

http://www.google.com             www.google.com

https://www.google.com/          www.google.com

http://www.google.com/            www.google.com

www.google.com                        www.google.com

 

Thanks

Shantanu B

1 ACCEPTED SOLUTION

Mark Manders
Giga Patron

If you can get the url from the email, you can try it with something like this:

 

function extractHostname(url) {
    var hostname;
    var url = [your way of getting url from email];

    if (url.indexOf("://") > -1) {
        hostname = url.split('/')[2];
    } else {
        hostname = url.split('/')[0];
    }
    hostname = hostname.split(':')[0].split('?')[0];

 return hostname;
});

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

1 REPLY 1

Mark Manders
Giga Patron

If you can get the url from the email, you can try it with something like this:

 

function extractHostname(url) {
    var hostname;
    var url = [your way of getting url from email];

    if (url.indexOf("://") > -1) {
        hostname = url.split('/')[2];
    } else {
        hostname = url.split('/')[0];
    }
    hostname = hostname.split(':')[0].split('?')[0];

 return hostname;
});

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark