Placing beautiful hyperlinks in ServiceNow emails (as many as you like!)
hey everyone welcome back to my channel it is so good to have you here today we're going to add some flavor to notifications standard notifications use uiref to create a hyperlink showing the record number but have you ever stopped to ask yourself what if the number is meaningless to the customer what if i want to send a bunch of links to all sorts of records what if the link i'm building isn't related to a task stick with me for a few minutes and i'll show you how to embed as many beautiful hyperlinks as you like into servicenow email we'll use the following scenario each week every user who's a project stakeholder will receive a link to all the relevant project status reports that they might be interested in to build beautiful links you need to know the url you need to send to most of the time it's going to look like this the important parts are the instance name table name and sys ids we can find the instance name of the property and we can use javascript to help us find the table and cis ids that we want you're also going to need a registered event since in this example we're sending a scheduled mail instead of a transactional one you'll also need a scheduled job to fire the event that will trigger the notifications you'll need a mail script which is where all the magic is really going to happen and a notification to actually hold all the pretty urls step one register an event we need to do this first so that the scheduled job has something to fire we're calling ours project.weekly.status now please be a good developer and fill out the fields describing the event and how it's triggered in our case we name the scheduled job and describe why it exists step two the scheduled job this will fire the events which will trigger the notification before we go too deep let's look at the data remember this is firing for every user that's a project stakeholder so let's right click on that table name god i love this feature show data now we're looking at project stakeholder records now here's the kicker stakeholder is not actually a reference to user if we click on it we'll see that it's actually its own record with its own reference to user this makes it possible for a user to be a stakeholder to different projects in different contexts we want one email going to robert so back at the script we declare an array for unique users then we make sure we're only querying active projects then we check to see if the project stakeholders stakeholder user is in the array of unique users if not we'll add that person to the array this is going to ensure uniqueness and will fire the event the event will send the user as parm1 let's execute this now we should get three unique users therefore three events should be in the event queue execute now and there we see the three events in our event queue if we looked up the sys ids in the user table we would also see that they are the right users that we want to send to step 3 the mail script this mail script is what's going to populate multiple urls in our email message so the first thing we're doing is declaring a variable to get us the instance name because we want this to work on dev test prod or any other instance that it lands on the second thing we're gonna do is embed that instance name in a variable called link base and this is where i'm actually constructing the bulk of the url so we're putting this instance right by servicenow.com and i've obfuscated a little bit of this code because i want the endpoint to be a little bit of a surprise but here is where you would usually go back to what a url normally looks like in servicenow then i'm declaring another variable called link text because this is what i want the text to be that the url is embedded in and then finally we're going to have a variable for link which is going to be the actual fully formatted beautiful url okay now we're looping back through the project stakeholder records to find all projects this user is a stakeholder for now we flesh out the link text which will be the text that appears to be hyperlinked here i'm grabbing the project stakeholders project and the project stakeholders project's short description separated by a dash now we start constructing our actual link which includes an href the link base variable and our link text to fully build out a link with both friendly text and destination be sure to add a br at the end so all links go on their own line step 4 notifications here we are on the notification record as you can see i don't care about the table since this is event driven on the event we created in step one project weekly status we're also using the user passed in parameter one as the recipient of this notification and in the message html we've put our mail script in let's see what it all looks like using preview notification beautiful informative hyperlinks let me click one here we are at the project status report but robert this isn't the project status portal you're absolutely right this is the fully configurable project status page that comes with vivid charts itbm content pack check the description below if you need higher degree of aesthetic control and better distribution of your project status reports with vivid charts so what was that url i had hidden in my mail script here we just entered the url for the vivid charts portal page we wanted along with the vivid charts dashboard and then prompt for a project id which we fill in in the link variable now that you know how to build hyperlinks to records via mail script just imagine what kind of rich notification experiences you can craft with a little more time and effort i'd take my project stakeholder hyperlinks and add emoji frowny faces if the project didn't have a status report or doesn't have one that was created in the last 60 days don't settle for mundane build something awesome i remain yours truly the duke
https://www.youtube.com/watch?v=LjUMF6c2n90