Modifying the ServiceNow Microsoft Outlook Plugin to Create a Record in Another Table
this video is going to look at modifying the service now Microsoft Outlook plugin uh in order to make it create a record in another table so service now offers uh this Microsoft plug-in which allows you to create a record uh either an incident um or a vtb um item or task um so what we want to do is we want to make that plugin uh give that the ability to create a story uh from an email so let's start at the end and I will just take a look at what we're going for here so if I'm in my email and I won't drag it all the way over uh if I'm in my email and I have this uh here's the service now add in because I already have it added in here and I'm clicked on an email right now so if I click on that I have three options so this is the out of the box options create incident or create vtb task uh and I added or this video is going to look at how I added this create story I click create story uh it pops up the uh story form gives me the number I can choose the product and puts the subject of the email in the short description and the body of the email along with the from sent and two and NECC uh and then here's the body in the description field so that's what the end result that we're going for I'm going to be following this blog post I have and I'll put the link in the description um which has basically all the step-by-step instructions for doing this so the first thing we want to do is activate the service now addin for Microsoft Office and I have a link to the documentation I won't go through that because that's simple enough the second thing we want to do is create a record in the Snore office undor control table so first of all credit to uh this site which I have up here uh which um explains how to create an HR case in service now add in for Outlook so this is pretty good it brings you through some of it but then it kind of falls off uh when you get to the widget piece so that's where I'm kind of filling in some of the blanks uh but this site uh definitely helped me on this first step anyway in terms of creating this uh record so let's go and a look at that table so we go office control. list and we can see that I already have this uh created here so there are four records in here here's the create incident the create vtb these are the out of the box records this is the parent um of those two records so if we go into the here we could see that um this is the type menu and then if we go into the create story record this is a type menu item um so label create story description create Story We link that to the parent control which I usually there's only one in there yeah called service now and the same manifest and this is actually linking back to that uh parent item that menu uh that we just saw before and then the Manifest here is in the service now for itm um you could if you around with this you could probably create your own manifest um and then have your own uh icon in here and and it wouldn't say service now it might say you know help desk or whatever else uh you're doing so that that could be interesting maybe for another video but for now we're just going to stick this in the same service now for itm and then you can get the um icons uh here which are actually listed in this article that I linked uh and I think they're probably just the same oops probably the same ones that are in the other um actually no I think they're a little different because yeah these ones have task icons anyway you can play with that uh array here so yeah this is just giving the now 16 icons and those are giving the task icons just to give you an idea those are these icons here um so this is just using the generic Now icon okay anything else in here so the other important thing is here relative URL um so I'm doing / snc Outlook which is the same for every one of them and the ID is the page that we're going to create so this is Outlook create uncore story uh so that's it for this once we have that record created uh actually let me just mention so there are a couple of once you create these records you can modify them because there are some ACLS in here which I ended up disabling uh if you go into the security rules and I think there's a right ACL on this and I think it's this one uh no these are the active ones so maybe I didn't disable this oh no what I did is I just changed it to True here so I cheated a little bit and uh rather than having to create another Hall record uh because I messed up some of the values uh I just put the answer equals true otherwise basically it won't let you modify because I think it creates the Manifest somehow that's the XML file that gets imported into Outlook um so it doesn't want you to change stuff but I I was able to change things and it's was fine for the Manifest so uh use it to your own risk I suppose okay so after we've created this record in uh SN office control now we're going to go to the table and in this case we're doing it on the RM Story table and we want to create a view called Outlook so that's simple enough um I go stories and we all know how to create a view you can do this any way you want uh I found I I put the view in the this same scope uh service now add in for Microsoft Outlook uh just to kind of keep everything in that scope um and so you see I have the Outlook view so this should be a single uh single column layout uh because basically whatever you put in here is what's going to fit right into this uh that keeps collapsing on me is whatever is going to fit into this uh little window pane here uh okay so that's the view called Outlook uh um I one got you here and this took me a while to figure out is if you have view Rules running on this table um and this table does have a view rule that uh forces it to the scrum view most of the time uh you're going to want to disable those or modify them so that you'll be able to call the Outlook view uh without a problem because you can imagine uh the scrum view in this Outlook pane over here is doesn't really work very well okay so once that view is created then we're going to go and and this is really where the bulk of the work is we're going to go and clone and modify the create incident portal widget so we'll go back here and we'll look at widgets and service portal widget um so the one we want to clone is called create incident and let's just just go in here before we clone it and take a look at how it works okay so we'll start in the server script and so what this is doing is because this Widget the outof thebox widget if you are logged in as an iil user and the first time that you uh when you activate the plugin and Outlook and you click on it for the first time it's going to ask you to log in um so if you are a if you're an iil user then it's going to give you whatever form uh well in the out of the box or this is the incident it's going to give you the incident form with the Outlook view right because you're a uh you're a um a fulfiller you're an agent basically so you're going to be creating an incident that way if you are not if you don't have the itail rooll uh that's where this else statement comes in it's going to go and grab the um catalog item with this sis ID uh which I think is yeah it's in a system property which you can modify it's going to go grab that catalog item and display that in the Outlook pane because basically you're a requester at that point and uh so you're just going to be putting in an incident um so um for this video or for this implementation I should say we're not going to be using this section because we're going to assume because we're creating a story that everybody is that's creating the story uh and we'll we'll look at that in a second so we're basically just not going to use this else piece I left it in there because I just left it in there but uh in the real world you probably could get rid of all this stuff and uh just use basically from lines 12 uh through 26 um so the other piece is over here in the HTML template uh um so we have a few different divs that display depending on here we got three of them depending on uh what's happening here so the first div is what happens if uh the data is not valid so when it goes and tries to grab the form then it just gives you this message you know hey I can't find it form not available uh the second div uh from line five is if you're itail then it's going to give you the um I tell it's going to give you the incident form and then once that form is submitted it's going to show this which is inside of this yeah right so this this div actually has two divs inside of it one of this is the show confirmation div this is uh in the end when after you submit it you're going to be able to go and uh click on it to to go look at it and we're going to have to change this line 11 um and the second div is right here starting on 16 and this is going to be where it goes and grabs the form actually and somewhere in here was here's the attachment section uh right here yes so the form modal uh comes from data. F so it actually uses a if we look over here in the server script yeah right here this uh uh dollar signp doget form right so it's going to go grab that form with that view and and uh so that's how it gets displayed over here and then the other div is if you are not iil and that's going to give you the catalog item basically and there are a couple divs inside there I haven't really explored that but it's probably the same idea it either shows you the confirmation page if you submitted or it just shows you the catalog item okay the last piece we're going to look at in here and again we're still in the out of the box create incident widget is down here uh line 107 in the client script populate Fields let's get rid of that uh let's get rid of that too so this is where the it takes uh so it's using the office JS library and it's taking the value from uh item here so this is window office context mailbox item so this is the email that you're clicking on and it's doing a set value for the short description so it's popping the uh subject of the email into the short description and then it is popping the body basically so it goes and gets the body and does some function and then comes back uh and it's sticking the body in the comments um which is kind of annoying and there are a few questions I noticed on the uh community site asking how the heck do you remap this because you know I want to put that in the description not in the comments um and we'll actually do that uh in this widget once we uh clone it okay so we're going to go ahead and clone this and I won't do it because uh I already did it but uh we all know this we just go here and do clone create incident and then once we do that that will create this widget so first thing we're going to want to do is we want to change the names here so we're going to uh open in platform and we're going to change the name from create incident to create story and then the ID is going to be Outlook creatore story uh we'll save that then let's go take a look around here at the different things that we did so let's start with the server script um so I left iil in here even though that's probably not uh the best thing it probably be better to check if you have actually in in this uh solution we don't really care what the role is we're assuming that everybody has uh the ability to create a story in here but um maybe a better way to do that would be you know check to make sure they have the scrum uh I think like story Creator role or something like that uh I just left it as itail and uh so this I left alone the only things I changed here are line 12 instead of uh data. table being incident it's going to rmore story uh everything else stays the same The View stays the same it's also called Outlook um yeah everything else stays the same here so really the only thing I changed is this uh RM story but you could change line four so it checks for the right uh role and not necessarily iil role uh the HTML template there is is just one change that's line 11 so this is the Once you submitted your record uh this is the the button with the link in order to uh go view it and so instead of incident. Doo It's rmore story. Doo simple enough uh then the a lot of the work happens in the client script or a lot of the modifications happen in the client script so from line 11 through 18 we're going to want to change these messages so instead of your incident has been created it's going to be your story uh create new uh view story here on line 15 Etc you can just use that um okay also in line in the client script and this is what I was showing early with the populate uh Fields function uh right here so populate Fields so what I did here is we can see in the example here that what I'm doing is I'm in the description I'm putting the from so with the email address the sent uh the two uh who it was to CC so I'm basically like pasting the whole email into the description field um I was doing this late at night and uh you know that's probably not the best thing it's probably best just to put the body of the email and description and then maybe put the whole email in the comments field uh but anyway I mean it doesn't really matter I'm just doing this for the purpose of uh illustration at this point so let's uh let's look at this so This I didn't change so the short description is the item. subject that's no problem uh That Remains the Same uh when I initially did this on line 118 I just had G form set value description result uh right descript destion so this was uh comment I think in the original one oh here we have it no we don't have it there yeah we do have it uh CSS body template here client controller populate field so this was originally yeah comments and I just changed that to description and that's probably what you want to do now I have this other thing that goes and gets the the two and and the uh sent date uh Etc so basically what I'm doing is I'm setting up this variable called the description or desk and I put from and we look at things in the item uh object so item. from. email address so in the article I [Music] have uh right here a link to the Microsoft dots uh docs page and documentation and this gives you all of the properties of that uh item object right so there's a whole bunch of stuff in here and we're looking to look at details by mode we want anything in the message read right so you can even get like the attachments from the message a lot of stuff going on here here's the body uh message read um so this gives you everything that's in there plus some methods okay so going back here I just did the from address and then the sent is the item. DAT created uh and then the two and the CC so because so the from is just one address right so it's just uh there's just a simple object in there but the two and the CC are actually an array so I created this function to just pull out the display name and the email address um in each of the two and the CC arrays um again if you don't care about that uh just ignore all this stuff and use what's commented out on 118 to stick the body of the message in the email uh but this is just some neat stuff and then at the end right I just set the value of description to this desk that I uh built up in these past few lines okay so that is modifying the client script make sure we got everything here that's the whole client script um and we did this modify the HTML template change the href at 11 to RM story right we did that okay so now we want to copy and modify the Outlook um Outlook home portal page so if we go back here and we go pages so service portal pages and we look at uh no not that one it's called Outlook home right Outlook home so interestingly they named it Outlook index uh I guess that was like the main that's probably the first thing they did right when they was like hey let's be able to create an incident from an email uh inside of Outlook so they just named it the in index page and then you notice right then okay they added vtb afterwards and now we're adding this create story so here's the page Outlook home and if we go into this in designer we can take a look at it and so this just has the Outlook uh logout widget up here and then here it has the create incident widget which we just cloned so basically we're just going to copy this page and again our clone it rather and I won't do this because I already did it and in the new page go to that in designer and so we just we're going to remove the create incident widget and add the create story widget which is the one we modified so at this point you should be able to uh be able to go to that page in the portal so let's go back let me get the link uh actually I think I have the link in my article here yeah so snc Outlook ID equals Outlook create story uh we'll head over here and let's do it in here okay so yeah you can't see that but I'm pasting that uh up into the let me move that down a little bit so here you see that's my it's in the URL there and very simple uh here's the logout widget and here is the uh story form uh with the in the Outlook um view uh so of course short description and description are blank uh because remember it's the client script that goes and grabs the subject and the body of the email and dumps it into here okay our next step then is to download the Manifest and install the plugin so there's a good support article uh which I have linked and that kind of takes through all of the steps um just we'll look at it quickly I think this is called office or is it Outlook yeah office add and manifests and here's our service now for itsm um so we can download that and let me see if I can pop that open you can have a look at it right so I have it here in vs code and we won't go through all the Gory details but you can just see so there's another uh so here are the well here it's it's really easiest to go down here and so we see the URL here's our URL right snc Outlook uh ID Outlook creatore story and the ID is this thing uh here are some of the short strings right we can see this create story uh this is the description Fields uh again I just put create story for both things so basically you can see it kind of uh you can see it in here uh there's not real I mean this basically service now builds this file for you so you don't have to uh worry about anything in here but it's just interesting to see what's going on okay uh so we downloaded that now we're going to head over to Outlook and install it um and I won't do that because the support article basically explains how to do that uh pretty well um one thing that I found is uh because basically you install the Manifest on the web and if you're then when you go back to the desktop client you have to close it sometimes you have to wait a little bit um and then reopen it and eventually you will get the service now uh I icon to appear here uh on the home screen uh and then you'll be able to do this uh right create this is the out of the box create incident and you'll have your uh out of the box uh create story so that is how to modify the service now Outlook plugin to be able to add a story and you can use this same uh pattern to create records in any table
https://www.youtube.com/watch?v=W7TRpD1x4RM