ServiceNow: How to embed hyperlinks in work notes | clickable links
in this video I'm going to show you how to add a hyperlink to a ticket in a worknote and we're going to do that from a business rule but if you stick around right about to the end we're going to see how we can move that to description [Music] so in one of the latest videos I did and I'll put an annoying link up there and one in the description as well so if you haven't seen it Go and we'll check it out but the point was we were syncing up work notes or additional comments are based on the kind of apparent child task situation so in that case it was a request item and catalog task and what we did we used a business rule or we used two business rules like this one here um the other one was on the catalog task of course and we sync the work notes to look something like this right so it's pretty simple um it's effective and it works so the work notes there's been a note added but what I wanted to do is is extend that a little bit there was some things in that configuration I thought well we can do that a little bit better we could one we can make the configuration a little bit neater um yes we did two business rules are we going to continue to do two business rules yes but there is some duplication in our code and there's one thing I don't like is when I have to rewrite the same code twice right so I'd always try and look for a function that I can call got us thinking maybe a script include I don't know stick around um and we can also make that better from a user experience point of view as well I think anyway so what we're going to do is instead of having a simple note that comes in here we're going to make that a clickable link so we're going to say a work note has been added but we're going to say what the task is and we're going to put a link or a hyperlink that we can click on that task and go to it so without having to do a global search okay alrighty so let's dive in take a look at these business rules so from last time you can see I've got two business rules here and they look relatively similar so we're going to look at tidying that up a bit later but for now we're going to concentrate on making those work notes a bit more fancy all right a bit more reader friendly reader friendly user-friendly um and by doing that we're going to identify the record that the workout originated from um and give it a nice little hyperlink that you click on it and it takes you to that rather than having to primitively type in the number in the global search so let's go and take a look at that um first of all what I'm going to do I'm going to put that on a business rule just keep it clean and then we'll put it somewhere else later on so stick around and find out where is it a flow um it's not a flight by the way it's not so let's do that so I'm going to admit to you some of it's going to be typing some of it's going to be copy and pasting because you don't want to sit here and watch me type um so let's have a look so we want to make a bit more formatted so what we're going to do create a new function I'm going to create functions um for this just to keep it clean and so I can explain to you as I'm going along so in this one we're going to call this function um message no we're not what we're talking about we're going to call it format message okay so in this we're going to create an array and we're going to pass in things into that array and we're going to pass in three things into this array there we go um why didn't I do that first actually that would have been easy wouldn't it okay and then we could just slide in the stuff so we're gonna create an array we're going to push some stuff into it and then we're going to return it okay we're going to return our array what are we pushing into it well we're going to need to push stuff in from the source record in this case it's going to be current and we're going to pass in the work notes as well okay I'm going to put in notes um you'll see why I'm debating it in a minute because you could argue I don't need to do this but I'm I'm we're doing it anyway we're doing it um so what we're going to push in so we're going to need to identify the source class display value I can hear you screaming at the screen I'm getting stuff wrong and my typos Source get display value what's that we're going to pass in the current um record in this case it is the catalog task um so the source.get display class display value is the display value of the table it's on so catalog task long-winded explanation this is going to be the URL and I fancy URL we're going to put that there for now and then I'll show I'll tell you why in a second um and the last thing we're going to pass into that array or pushing to the array is the comments themselves or notes and that is a parameter that we're passing in so let's do something with this URL so we'll call this get URL we're creating a new function and in here I'm going to cheat um if you all just turn away for two seconds ready there we go I've just typed it all um that's an absolute lie but I've got a possession with keeping that neat um so we're going to pass in record um in fact to keep it to keep it nice and easy for you and we're going to pass in Source again just so you understand it's all the same thing you could call it whatever you like to be honest but we'll keep it a source and then we're going to call that function from here and then we're passing in source but hopefully that makes sense so what we're doing we've got an array here that's been constructed in that in line 22 we're calling this other function and what's this doing this is um again pause the video um screenshot this or take some notes or type it down and keep it in a script repository I've used it loads of times this is a nice little function to construct a URL right so that takes you or whizzes you out to um uh a ticket okay so we've got um The Source get display value so that's the display value of the ticket um the table name um and then we start constructing the link of the the ticket itself and we throw that back into the URL parameter parameter variable now what you will notice and and it is equal to the HTML tag the href in here but what you'll notice which is additional is this little code here if you know HTML tags you'll notice um more often than not you'll see something that looks like that right so what we need to do is just wrap it in those code tags um just so it renders nicely in the activity log okay in terms of a hyperlink otherwise it'd just say ahref okay then we're returning that URL back into the array okay so let's move those other way so we've done those two functions now so what we need to do is call those functions and pass stuff in so up here we're going to call that function and we're going to send it in current right current in this case e is going to be source and notes in this case is going to be current wood under the okay we're passing in current and then winner then we can call that we'll give it a bar oh message okay like that and then here um we could do um message no we're not actually in here what we're going to do is make this a tad bit more fancy we're going to use this I've done a video on that actually um I'm going to pass that in so I've done a video previously again I'll put an annoying link up or something in the description if I remember when I'm editing the video but in get message you can pass in if you didn't know and this is really clever you can pass in um Dynamic variables or dynamic things into the message so zero in this case will be equal to um this so request item catalog task one in this case will be equal to whatever this is so the URL okay and actually that's going to be the number get display value is going to be the number or the ticket number and number two is going to be the notes so this is actually going to say 0 by substituted for catalog task it'll say catalog task one which means the number of the catalogs are so the catalog task c t a s 1079 has been updated and then it will just give you the note that looks a bit nicer right and that's what that will look like so the last thing I think we need to do is look about how we can make this a bit more scalable how how can we minimize duplicating our effort right because in order to make this kind of logic this nice new sassy logic work on our other business rule which was for let's just remind ourselves request item we could absolutely just copy that and then change these bits at the top here to match um and that would work but if anyone's ever worked with me they'll know this but I I I don't like writing the same thing twice if I can help it of course I understand there's context where you're going to need to do it um you're gonna need to uh you know judge every situation um at the time and just and and perhaps have a discussion of do you need to create um the same function in in multiple areas um and sometimes because of scope you might have to do that on waffling but my point is I always like to put it in some kind of centralized place that I can call it from other areas right so for example this get URL you might not just it might be something that you can use um not just in these types of business rules for populating work notes okay you might want to grab it from other types of Records not just request items perhaps incident perhaps changes we discussed that on the last call oh anyway I hope you're getting the point um so I'm going to put it somewhere Central that we can call it so I'm just going to remove that so what we're going to do anyone knows what we're gonna do well the first thing we're going to do we're just going to change screens to give us some more hey that's what I'm doing right give us some more space so we're going to go for a script include to lavascript include so we're going to create a new one and I'm for the purpose of this I'm going to call it request item utils and then I'm going to give it a description I always liked you I always like to you've got to give them descriptions so I'm going to give it this one uh almost as good as this is some comments now what's the problem with calling it request item utils and this is how we've got to start thinking people so we've got this get URL and this format message um it's just constructing an array nothing fancy these aren't specific to request item utils and will would we want to use this get URL somewhere else quite possibly yeah so would it be logical to call guest or get request item utils it might be a bit silly people might not look for it there um just a thought you might want to have a centralized util so you call from request item utils and that's how you should start thinking about stuff I love these debates by the way so what we're going to do is going to take these functions we're going to pop them in there we're just going to change the format and sometimes I don't remember the format the functions because they change depending on what the client callable or not um so how do I remember well quite simply I look at something else that's there or just look at this initialized function at the top right it gives me the format so you just cast your over there the corner is in and I'm obsessed with keeping that neat so that's what we will do what else do we need to change well this format message function if you remember it's calling the one underneath it this get URL so what we now need to do is just say this so this script include this entity this thing that we're on dot get URL but this we're already there dot qrl and that will do for us that now we need to initialize and initialize that script include and call the function from visual so I'm going to copy the API name and we are going to Simply we'll put it here I'll split it up make it make it easy s-i PSI bit of PSI that will initialize our script include like that and then we'll quite simply say script include Dot function so we've now put that function somewhere else so we've got to tell it it's somewhere else and this is where it is so scripts include um Dot message you could do belts and braces like um you know things like if if this is null then insert like a default text or something you could do that but let's say that the last thing we want to do make sure it all works because we don't want to throw something over the fence to test us to then come back and tell us it's not working never do that so let's go to item let's go and play with the one last one I did it was a catalog task wasn't it the business rule um was it yeah catalog task okay so now what we can do is go tests um some notes Here and pray that it goes up because we've never been in demos where we've gone to show something and it stopped working here we go right so now what we have a nicely formatted um message so now you've got catalog task which was our zero inside the array we've got the task number which is the link which was our one inside the array and then has been updated with and here are the notes which is uh number two in there when we click on that it'll launch us out to the task okay how nice is that for someone that's assigned to the ticket they can just click all around the tool um it's almost trying to make it easy for them okay so there we have it we've now got a catalog task which talks to a request item and back again if we need to but it's using the hyperlink this time as well that's the difference between the last video in case you weren't keeping up so I hope you found you it useful if you haven't yet subscribed please consider doing so there's no hard sell if you have and you haven't yet you should just hit the Bell icon that's it yeah smash the Bell icon you'll get notified when I upload new videos just like this one until next time um through happy low coating [Music]
https://www.youtube.com/watch?v=tlCKSPD8IBQ