logo

NJP

Getting started with the ServiceNow SDK: Installing the SDK, creating and deploying a sample app

Import · Mar 10, 2024 · video

this video is going to look at the service now SDK and we're going to be following the instructions here in the documentation for creating a um I'm going to be creating a test application by following the instructions here so uh this video is not a theoretical look at service now SDK it's actually just going through the procedures for uh creating an application um with a module and looking at just digging around and seeing how it looks once we're in there um so I guess a bit of warning if you have already installed the uh SDK and you uh did a test app already by following the instructions here uh I'm not really adding anything to the equation so you can move on to the next video uh but if you haven't done this uh or you're having some trouble getting this to work uh this video might be helpful to you this is the uh I did this once so this is the second time I'm doing it and uh hopefully we won't run into too many snags along the way so first thing is to fire up the documentation and uh I'll put a link to this in the description and uh we'll want to go to the service now SDK so they start you off with some theoretical stuff and I won't uh go over this you can read it yourself uh service now SDK benefits again I won't go into detail here but if you're watching this video you probably know what the benefits are uh I mean this thing I'm super excited about it because we'll be able to use uh third party libraries you know to do all kinds of stuff that we've always wanted to do in service now and uh couldn't do uh hopefully this will be the the solution for that um I will also point out that there is a great uh video uh from the service now Community I think it's the uh I don't remember what program it is is but uh they have the sort of program managers behind this SDK they do interview with Chuck tamasi I think for like a good 50 minutes it's really awesome uh so definitely check that out okay so let's get started here we're in the service now the documentation um let's head over to install the service now SDK um so first you need to have no JS and uh npm uh node package manager V8 or later um so there are probably 8 billion videos on how to install nodejs uh so I won't uh I won't do that here I've already installed it myself I think I have like version 20 or something and then same for npm there's also uh also you know 8 billion plus videos on how to do that so you can uh just install that on your machine um okay so then they give you some helpful and and this is actually helpful we will do this we'll just make sure that uh npm the correct version is installed so you can go node DV and uh right so I'm running 20.9 do0 so that fits the requirement 16.6 do0 or later and then npm DV it just takes a second or two to fire up but we will see the result is uh we have it come on there we go yeah so I'm running version 10 okay so the next thing we have to do is install the uh service now SDK which is actually just a module um and they have you can just copy pasta this right out is running from it's running in global so it's not going to run in any um if you don't have that Global uh option it's going to install in whatever folder you're in and we don't want that we want this to be in global so again back to the command prompt and whoops right we just copy paste that thing right in there it'll probably tell me uh it's already installed or something like that let's see okay so that's firing up it's actually just going to install over what I already have okay so I did uh pause the video and just unpaused it so you didn't have to watch the progress bar um so this is what it looks like after it installs uh we are getting some errors here about uh or some warnings I should say that uh these service now modules are require 16.16 but the current is 20 I'm not sure why that's happening because theoretically a later version should be fine but uh anyway and it doesn't impede anything from functioning but uh just so you know you probably will get These Warnings um and uh but at the end we have uh and my mine says changed because I think we I already installed it once um but in any event you should uh end up with something like this okay so now we're good we have the SDK installed uh so let's go to create or convert an application and we are going to create a new one here so me bring up my window again here and we can start the SDK with um now- SDK I don't remember doing this before I don't know what that does okay yeah this just brings up but I guess this just make sure that it's uh actually installed right you get a list of commands and things you can do here um so we're going to be using this now SDA create but actually before we do that we're going to use this now SDK off so what this does is it stores your credentials for a non-production instance on um locally here so that uh when you build packages and you um you you send them to the server it will uh just you know you have to punch in your password every time um so we just have this here and we can just even copy the example okay so put that in there [Music] and go back over here so now- SDK and then we're going to use the O right um and then save command okay so here's where we get uh so where it says Dev user one this is where we're uh we can create an alias for it so let's just call this um uh what do we call this admin because I want to make sure it copies over what I originally did so that I don't have any problems here so admin uh then-- host you leave that uh then you're going to put the uh the URL of your instance um so uh let's see I guess I'll do that I just don't want this thing to complain to me all right all right so I will just type it in here so 64 718 okay my username and a generally bad practice to have your instance Exposed on YouTube for all to see but this is a PDI I mean if someone breaks into it they they can they steal whatever is in there there's nothing Secret uh so the username is admin and then we leave the default I oh oh yeah okay so this is going to be the default that we connect to right so we'll leave that uh flag in there and we'll hit enter it's going to go up to the instance and then it's going to ask me for the password so this takes a few seconds to run oops okay so here we have a problem from more information um I think what happened here is oh no here we go whoops yeah okay we're good so oh yeah okay yeah this was uh when I ran this thing before all right so now it's asking for the password and it's been put is masked so you can't even see where the cursor is you just kind of make sure that this is the active window and then punch in your password okay and then punch in your password let's see this going to work okay so I did not punch it in correctly let's try that again I'm going to run the same thing okay it's going to ask me for this so let's try again okay there we go so I got it right that time and then we just get this successfully stored credentials for instense great so now we're good we got the credentials in there let's go back to our procedure here so now we will use the create command to create a new project um so again we just copied right out of here do this okay so now SDK create that stays the same and now we have to name our app so let's call this one let's just leave it example- app uh now we have to put our scope in here and I'm not sure if um it's it's always going to be X underscore but um I went and grabbed the actual scope from my uh instance and let me just find that yeah here we go I don't know if you have to do that or not okay so that's the scope for that instance um and then we'll do example and I'm not sure if hyphens are okay in there I'm going to just do an underscore to make sure and so this is the scope name and then D- interactive all right let's just go back here make sure right project name and the scope name those are the only two things we need okay we hit enter there okay so here we get this uh bootstrapping a new service Now application project now I think that it will create a folder for this um example app in whatever I'm in right now so right right now I'm in my own uh user route sort of Michael local and it should create a folder called example- apppp um where it's going to put all of these uh it's going to put all the the files for this project okay so I paused the recording just to not subject you to uh having to wait uh and now it's going to start asking you some questions like uh the description for the application and so you can put anything in there example app and build and register application on the instance right so do you want to uh up build it basically and send it up to the instance right away and we're going to say the default is yes so we'll just hit enter um and now it asks do you want to add a sample table so last time I did this I said uh no uh because that's the default but this time I'm going to say yes oops application uh scope name is invalid okay so there you go that is uh that's the answer to my musing my question before about uh does the scope name have to be valid so um I wonder what the problem is is the uh 462 323 462 323 I wonder if this extra underscore is what it doesn't like let's try taking that out ah maybe it's too long as well um let's see I can't remember how long it can be but let's just call it XA see what happens here okay we'll do our description and I'll just except the default register on the instance yes uh sample table we're going to say yes okay so that time it's good now it's uh bootstrapping and right it's creating the folder yep example Dash app okay now it's building it and it's going and looking out for any dependencies so normally I mean we just bootstrap this thing so it doesn't have any actually I think it has one dependency um but uh if you then uh built you know you uh installed a bunch of third party uh modules um the build process would just make sure that everything is is good to go before sending it up um so it did it it so it built it and deployed it to the instance um so we can go take a look at it uh up there and uh down here locally uh let's just keep going through here and see if there's anything else okay so then the next thing is if you actually want to add some thirdparty modules or whatever uh so in this video we're not going to do that we're just going to take a look at what the example app is um that they that they give you so let's first take a look at um let's fire up visual studio code here and vs code and we will open our folder up um so again it's in the F whatever folder I was in and we should have something called the example app we'll open that folder okay so this is our example app and here's the folder structure right metadata now dist um so source is really the main show here this is where the example function is this my function um actually before we go into this let's just we go back to the documentation so the documentation if you go to the service now SDK the sort of the root to this I think it's here that yeah right here application structure it explains uh each one of these folders uh and you know the purpose of it and what's in there basically uh so that's really helpful I won't repeat that stuff here but just so you know that's there um so we have this my function and this is the example that they give you and we're going to go take a look at this on the instance in a minute but uh we see it here so it's importing this module uh Glide and Export so this is what will be visible to uh this application and other applications in in service now once it's up in the instance uh this um function show status update and this function just has a very simple uh add info message which talks about the old status and another info message with the new status and we'll go take a look at that uh in the instance so that that's really in this folder the source fold this where your functions are going to go um and then I'm a little bit getting ahead of myself but I believe it's in this folder where you're going to um Define what the you know what I'm going to shut up because I'm not sure that that's what the case is but somewhere you have to Define uh what you're exporting all right now let's head over to the instance and take a look at how it looks up here so if we go here and we go to um well either CIS scope or my company applic or actually let's just go to Studio uh we can see this uh example- app right and right here's the um the scope right so we fire that up and we can see there's our sample table here to do okay and there is a sample uh business rule logic item change so let's go over to here because this is where it's this is where it gets interesting um so we have this business rule which runs on the to-do table right and it it's an after business rule on any update and the script and so this is where it gets cool is uh so here is our our constant here's our our function basically um so it says show status update and require this uh code right Source uh my function now if you remember when we were in here uh that's uh right here so source and my function right so it's saying hey go get this uh this function which is the function that we exported here show status update okay so then it's going to call that function uh show status update and it it takes two parameters which is the new status and the old status uh the new status is here get value from the status column and previous uh get value from the status columns right so status column is just a column in this custom table um and so actually when you do this uh if you build the application or when you if you create the application using the the uh CLI and you don't you choose not to do the sample table it will put this business rule on the incident table uh and the incident table doesn't have a status column so you you it it does run but you just get you know null values basically because there is no status column uh that's why I chose to create cre the table the next time around so um let's watch this thing in action let's just go look at this so we'll go to this table and we'll create a new record here uh we'll call this uh original status really barebone here they didn't even uh make this a choice column okay it's what's going on with that we submit okay and if I change this to new status and I save it right here I get my uh two gs uh remember from down here info messages record updated old status is the old status new status is the new status uh we get those two things here uh so the that business rule is calling this uh function that we built uh theoretically here in uh in uh VSS code and then uh you know built it and then deployed it up to the instance so this could have been some sort of uh thirdparty library that did a whole bunch of stuff and then we uh then we sent it up okay the last thing we want to look at is where is it uh so this require thing right how is that uh getting up here and so in the documentation they talk about let's see if I can find that again um installing developing they talk about the table where that gets sent up to uh I can't find it again uh anyway I won't go looking for it because I have it in my history here so it is in the table Yeah ecma script modules which is [Music] um gosh what is the name of this table right this is in the new one uh CIS module yeah let's see assis module. list yeah okay so assis assistor module. list brings you here and so this is the first app that I created this uh test app here let's maybe add a couple more columns here sort I created um so there are two of them right uh one of them is the package. Json and the other one is the actual function right so here is I don't know if we can click on this yeah you can and so here's the actual function ah and it's yeah you can't change it up here right uh so ecma script modules for scul applications must be managed using the uh fluent SDK so you can't uh even though you can see it up here right I can see what this is doing you can't make any changes here and that is mentioned in the documentation that the changes need to be made in vs code uh because it uh builds it the SDK builds it and it probably does some checking to make sure things are compatible uh before it sends it up here so you can only see it uh up here but you can't uh make any changes to it um so when you're in that business rule and you're doing the uh require uh it's grabbing it from this table basically from this module table and uh and calling the function from there so this is super exciting uh because I mean like I said in the beginning all that stuff that we wanted to do in service now that uh there was probably a node package for and uh you know and we said ah and maybe maybe you're like me you tried to get it fit it into a script include and then you know just gave up after a while uh that should be a lot easier that stuff because we can actually build the stuff in uh in vs code and then uh you know import it into there import them the modules and then uh build them and deploy them into here so uh super exciting uh there's a lot going on in this documentation and I hope to make some future videos on actually using some third party libraries and uh and putting those up

View original source

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