logo

NJP

Visual Studio (VS) Code Integration | ServiceNow Tutorial

Import · Apr 07, 2022 · video

[Music] my name is elijah armula and today we're going to be installing the servicenow extension for visual studio code first things first here we're going to want to go ahead and navigate to visual studio and open up the extensions menu we can search for service now a few items down we should see servicenow extension for vs code you can expand that should be able to see it from the search menu we'll go ahead and click install once it finishes installing you'll want to open up the palette menu on a mac it's command shift p if you're on windows it's ctrl shift p we'll want to use now activate now extension should activate pretty quickly once it's done you'll want to go down in the bottom left hand corner and click setup workspace i already have a folder on my desktop for this go ahead and click it and select project folder once that finishes you should see create project in the bottom left-hand corner as well it's going to need a few pieces of information from you first is your environment url and then a username and password to authenticate if you're going to use basic authentication so i'm going to navigate to my pdi here and copy my url go back into vs code paste it in and again there's three different types of authentication i'm going to be using basic for this enter in my username perfect so once we're authenticated here we have to go ahead and select a project type so we can use store applications or custom applications i have a custom app that i've already created in my pdi for this go ahead and click custom apps and then we can click import existing and this is an employee request custom application that i already have configured on my pdi so go ahead and click this and then these are the different types of file types that we want to pull into our workspace i'll click ok and it's going to go ahead and download all those here so you can see underneath my project folder we have employee request and then we have a few different folders here that get created background script scratch and source and there's some other folders deep down in this hierarchy so now that we have it set up one of the cool features that you can use this for is to edit code directly from your instance and then sync it back with your environment so we can open up our command palette again we can do command shift p on a mac or ctrl shift p on a windows computer we can type now colon and we can also see all the different types of things that we can do from our command palette so in this case we're going to go ahead and create a new file and we're going to create a script include and for this one we'll just create a my request utils file once we click ok we get our boilerplate script include code which is good it's exactly what we want and from here we'll just create a dummy function just for the test call it test log we can say we'll just go ahead and log it worked i'll go ahead and save this file and so from here we have it saved locally but it hasn't synced with our environment so we have two options at this point in the bottom left-hand corner you'll see sync file and sync project if we want to sync our entire project in custom map we can do that or we can just sync the single file going back to the command palette you can also do it from here as well so we can search now sync and same thing we get current file or current project so we'll go ahead and click sync current file so this thing says it was complete so we're going to go ahead and navigate to our script includes module within our instance and we can see right there my request utils and it was created just now so one other cool thing that you can do with this we'll create another function is we'll just call this test log2 we can create changes in our environment and then sync them back locally as well so we'll go ahead and create this change and we'll save it we'll navigate back over to our visual studio code and we can we can see here we don't have our second function we just have our initial test log function that was created so we'll go ahead and click sync file one more time it actually pulls in those changes that we created inside of our servicenow environment another thing that we can do from here is we can actually look up files so say you don't want to create a script include or a client script directly from visual studio but you already have a file in your custom app that you want to edit you can also just look that up so we'll open up our command palette again command shift b we'll search now global file search and we'll click enter and then from here we can search for different files and pull them up so we'll go ahead and go back into our script includes and this will pull back a list of all the scripting fluids that are inside of our environment so from here we can pull any one of these script includes directly into our instance here and we could edit them directly if we wanted to we'll go ahead and click on call rotation click ok just for the sake of this example and so it pulls our code directly into our environment another thing that you can do directly from visual studio code is select the update set that you want to work out of so we'll go ahead and open up our command palette again and we can look for select application update set so in this case we only have our default one but if you had more than one in here you can specify directly where you want to make the changes from in vs code we see here that our change update set to default another cool feature of vs code is how it manages conflicts with the same file so we have the most updated version of our my request util script in vs code but let's say that we go to our environment and just go ahead here and delete these two test logs let's go ahead and save it we have our empty script include let's navigate back to vs code and now let's just try to sync the file one more time since we didn't have the most recent version when we attempted to sync this time there's a conflict so what we can do is we can open the conflict here and it'll give us a breakdown of what the problem is so we see here that the local file in our environment it doesn't have any of the code here on the left but on the local version we have our two log statements from here we can go back up to the top and click sync current file again and it'll give us an option so we can overwrite the server or we can overwrite the local file so in this case we'll go ahead and overwrite the server file so that we still have all that code and so we see here overwriting my request utils in the server and if we go back to our server file we can see that it was updated and it has the most recent local version one other really cool feature of this extension is the ability to run background scripts directly from your code editor so in our file hierarchy here we see background scripts and script.js we'll go ahead and click on that and then from here we can directly write code and then test it in our environment without ever having to navigate back so we'll just do a quick log statement here hello world and then we can click the run button up here in the top right and we get our print statement right here and this isn't just limited to you know log statements or anything like that anything that you would normally run in a background script queries checking data anything like that you can do directly from vs code so i hope you found this quick tutorial helpful if you want to learn more about it you can navigate to the servicenow documentation and it'll provide all the features and functions of this extension go ahead and open this up really quick but if you go to docs.servicenow.com you can search for the servicenow extensions for visual studio code and from here it'll give you a quick overview of all of what you're able to do with this extension i hope you found this helpful thanks for watching

View original source

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