Need to add dynamic link in notification

Ashwini8
Tera Contributor

Hi All,

I have created a notification on user table so when a new user is created it should trigger notification to a department head to add few more details and i have provided the link in the notification that link will redirect to service portal and opens a catalog item. But i want to add it dynamically when we move the code to different intance also it should work.

Notification detalis

When to send : Record Inserted

Who will recieve : department head

What it will contain: http://details.about.thelink. It will resirect to portal.

Please suggest how can i achieve this.

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Tejaswini,

 

You can simply pass it as below.

Where sp is my portal name & sys_id is sys_id of item which ideally will be same across instances thus making it dynamic

find_real_file.png

 

View solution in original post

7 REPLIES 7

Slava Savitsky
Giga Sage

Instead of hardcoding the instance name your email notification, use gs.getProperty('glide.servlet.uri') to dynamically grab the URL of the current instance.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

If you are giving the link in message body then check what Jaspal has mentioned about relative URL

If it is in email script then you can use this to get the instance name

var instanceName = gs.getProperty('instance_name') ; // this would give you instance name

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

-O-
Kilo Patron
Kilo Patron

Relative URLs in notifications will not work, cause those end up displayed in an e-mail client - where there is nothing to be relative to, or in a browser where it will be relative to the current page (e.g. google.com or yahoo.com).

You need to create a mail script and build the URL in script, using @Ankur Bawiskar 's method to determine the current instance.

E.g:

template.print(gs.getMessage('https://{0}.service-now.com/{1}', [gs.getProperty('instance_name', 'example'),
                                                                 'sp?id=...']));