logo

NJP

Make beautiful #ServiceNow journal entries with embedded hyperlinks and emojis!

Import · May 29, 2022 · video

hey everybody welcome back to my channel it is so good to have you here the servicenow toolbox is back and in this episode we are going to talk about making your work node stylish so we are going to cover things like the code tags we're gonna talk about embedding hyperlinks and we're gonna have an extra special style bonus at the end of the show i'm gonna be walking a script through various levels of maturity so if you're new to javascript on servicenow this is also gonna be an excellent tutorial to step you from the very basics into something just a little bit above the very basics the scenario we're going to work with is program management now if you've looked at the spm module some people used to call it the itbm module some people call it the project and portfolio management module you'll know that programs are essentially mega projects think about an organization that is trying to become gdpr compliant and they have tons and tons of apps each one needs to become compliant on its own and maybe most of those will require a project in and of themselves to become compliant so in those cases corporations set up what's called a program which is like a mega project containing all the regular projects within it that's the super super basics of program management and what we want to do today is for a program manager to go to the program record and this is what it looks like out of the box and i want them to see regular updates about the projects underneath the program so we're going to do that via work notes programs are tasks so the first thing we're going to do is add work notes and the activities log to the program now we have work notes and the activities log and as we suspected there's absolutely nothing in it okay the first thing we're going to need to do is write a script that will populate the list of projects into the work notes of the program and i just want it really simple i want the project number i want the project status and i want the short description and each on their own separate line so let's open up our background scripts it's very likely that your background scripts looks a lot different than mine that's because i'm using sn utils sn utils is one of the best tools out there for servicenow developers and admins it's a browser plug-in so you don't need to worry about installing it on anybody's system it just works in your browser i've also done an interview with this creator arnold kui and that should be coming up in the top right hand corner and the link will also be in the description below please do not miss that episode it's absolutely fantastic so i don't want you having to watch me write this all out so i've run this code prior to and i'm just copying and pasting it into the background script but we're going to go through it line by line for those of you who maybe don't know a whole lot of javascript for those of you who do know a ton of javascript know exactly how you'd write this check the bookmarks in the description below so you can skip ahead all right so the first thing we're going to need to know is what program are we dealing with so we've declared a new glide record variable called program and it's going to the pm program table and it's going to get us a very specific program that's the cloud transformation 2022 with the program manager of george tuckus we also need to know what projects are associated to that program now just going back to this record this is in demo data too so you can build this out on your own pdi i know there's uh nine projects that relate to that program so that'll help us know if we did this right or not let's query the projects we're gonna have a new glide record called projects here going to the pm project table and we are only going to get the projects where the primary program that's the reference from project to program is equal to the program cis id that we just defined in this variable up here i'm also defining two variables and leaving them blank status prefix we don't necessarily need right now it's just going to be a foundation that we keep building on as we ramp up the complexity of the stylish word notes thing to add is going to be useful within a loop because it's going to add the new lines to the work notes that we're going to attach to the program and on that note worknote builder which we currently define as a line of text weekly project update zero zero one slash n that slash n is to make sure that after it writes that line it puts in a carriage return now work note builder is the vehicle that we're just gonna collect all this stuff in and then when it's finally ready we are going to push that to the program's work notes so in our while loop for all the projects in the glide record set so projects.next we are going to set the status prefix to the project status we are going to define think to add as a string and that's going to capture that number dash status dash project short description and you can see that we've got status prefix in there in lieu of project.status and then worknote builder is going to be that thing to add plus a slash n to make sure that it does a carriage return underneath and when all that's done we're going to take the program work notes and set that to work note builder then we're going to update the program let's see this in action i ran the script i come back to my cloud transformation 2020 record and there we have the data in the activities problem is it doesn't look pretty at all [Music] we can do a lot better so here we are back at our background script and the only alteration we've made to this is to the work note builder initialization so instead of just having the plain text now we have code h2u and h2 and u and code and what those code tags do is allow you to put in some sanitized html there are resources out there that tell you which tags you can use specifically for the code tags i'll try and get it into the description below but basically you're not getting the full suite of html you're just getting uh assorted stuff but that sort of stuff is gonna make a huge difference the fact that we're styling weekly project name as an h2 and we're underlying it you could use spans you can use paragraphs you can use all that kind of stuff so we're just gonna style it this way and see how that works for us so i've run the script and you can see that the title is already a whole lot better weekly project update two it's styled as an h2 and it's underlined it's bold it's eye-catching it's already way better than the previous version that we had down here yeah but robert it would be way cooler if the statuses had the actual color instead of just the name no problem i'm just gonna come back to my background script and here i've got a new version ready in this version we have a new function that's appearing called get status prefix while i'm going project by project in that glide record query i am going to call that get status prefix and i'm going to feed it projects dot status now what does this function do first thing it asks is the raw status red and if it is let's drop in one of those really interesting code tags and style the span so that his background color is to mate okay then we're just going to type the word red then we're going to end the span and end the code then we're going to do the same thing for yellow and then else if and then if it's not red or yellow then we know it's going to be green so we're just exploiting the code tags that we just learned about and putting background color to the words that we're using for the statuses let's go back to this while statement and status prefix we know is now equal to the calling of the function and whatever the function returns we know that the function is going to return a red yellow or green word that's stylized and so uh stash prefix is already inside the thing to add so we don't need any further changes let's run this script and see what the results are things are already improving we have a weekly project status update title which we did in the last session and all the status words now have a color behind them but we can actually make this a lot better yeah but robert i need to go manually find those projects now no problem here we are back in our background script and i've added some new stuff that's gonna make this even more awesome so now you'll notice i added a variable called source link and it's undefined until we get into the while loop and while we're in the while loop we want to make a url to the specific project and we're going to do that with this slash pm project dot do question mark cis ids is basically loading a parameter into the url what sys id do i want i want the sys id of whatever project we're on in this loop now that's going to be a url the service now is going to know what to do with it but we got to embed it in a hyperlink which we can do because we now know about these code tags so i'm breaking up the thing to add a little bit so we can deal with this kind of in easier to digest chunks so the first thing it's going to do is write down the project number space dash space and the pro and the status prefix which we know calls that function then we are just going to add to that this line of code so we are putting in quotes a space dash space then we're initiating our code tag and we're doing an href and what are we going to href to we're going to href to the source link and we also want to make sure that when this hyperlink is clicked it opens in a brand new tab so we're also putting this target equals blank now you'll notice that there's a mix here between double quotes and single quotes this is really handy to use both of them because i'm using double quotes for the main block and then in instances where i have to use quotes inside of the block i'm using these single quotes so target equals blank fits nicely inside of those quotes and then i'm going to add the project short description and then i am going to finish off the href tag and then finish off the code and then slash n to make sure we get another line then we are going to take that and add it into the work note builder and you notice the work note builder is doing plus equals because every single iteration through this loop is going to add a new line then it's gonna push all that to the work notes and it's gonna update the program let's give this a look okay now we have our weekly project update fourth iteration and we have the statuses in the colors just like our stakeholders asked and the hyperlinks are embedded into the short description of the projects that we put to the work notes and let's just give one of these a click and awesome it's opened up in a new tab yeah but robert i really really need to know which of these have been updated in the last five days or not sure here we are back in our background script and i've pasted in the next version this version has a function called days ago summary and it is going to be fed the last the last update where it's going to be fed from from the while loop so now in our thing to add we have a plus equals so it's adding to whatever is already in thing to add and it's calling the days to go summary and it's feeding it the cis updated on of the project whose iteration we're on so let's go back up and see what that function actually does first thing it does is figure out what now is so it's going to be a new glide date time and it's creating a summary variable which is going to be defined as blank for right now because it's not always going to be filled in then we're going to take a date diff between the last update which has been fed in and now and the third parameter true make sure that it outputs in seconds then we're going to see if the date diff is over 420 000 which is the number of seconds in five days and then we're gonna send in a summary that is code formatted so it's going to be code the span style is going to be color tomato and it's going to be strong and we're going to say it's not updated since we're going to break the quote and we're going to add in our last update which is fed to us and then we're gonna add the uh end of all of those tags the strong the span the code and then we are going to return the summary where is it gonna return to it's gonna return to our while loop and as you can see we have this thing to add which we've been building and building on top of and we're going to add a little bit more to it the days ago summary whatever that returns plus a line break then of course we make our worknote builder equal to the thing to add and i'm going to pump that to the work notes and update the project let's see it in action running the script and we see that none of these have been updated in the last five days fantastic should have planned that one better with the demo data okay one last way to spice up the work notes and add some uh flavor we are actually going to take out all the words for the project statuses and we are going to embed emojis so before i go to my background scripts i'm going to go to a website called getemoji.com link is going to be in the description below and this allows you to search for all the valid emojis i'm going to search for circle and i have a broad range of circles and colors i can pick from let's grab red circle copy it go to our back to our background script and in our status prefix instead of all this code nonsense i am just going to return a red circle gotta be in quotes though because it's a string do the same thing for green do the same thing for yellow alright that's a lot cleaner and easier let's give it a run and see what happens all right weekly project update 005 and we have nice little colored pips instead of the words and there you have it folks with the use of code tags and emojis and really clever ways of working with the ahref you can embed urls you can colorize text and you can add emojis into the text as well hope this helps you build some phenomenal updates to work notes and get people the information that they need right when they need it in a way that doesn't feel like i'm chewing broken glass through my eyeballs thanks for watching we'll see you on the next one if you're a servicenow expert looking for better opportunities but maybe your resume or linkedin profile isn't doing you justice reach out to me via linkedin or the email pictured here as i offer both career coaching and recruitment services and if you're a servicenow customer or partner you heard that right robert fedoric now does servicenow recruiting with a 1500 subscriber youtube channel and mailing list and thousands of linkedin followers let's make sure your open positions get first go with the prodigious pool of servicenow resources reach out via the emailed picture here

View original source

https://www.youtube.com/watch?v=oYi0Z6gKDi8