[NOW-SDK walkthrough pt. 1] Setting up the ServiceNow SDK and CLI in the Washington DC Release
[Music] but I want to recreate what I did just in case people are watching and want to see it I might upload this to YouTube too um because the the SDK is different in the Washington DC release and so there's some cool changes and I wanted to try them out and it was working so let me dive right back into that so first of all I have this um IVs code open it's my normal code editor that I use for everything I've already created a folder for uh this scope already so you'll see that I called this this folder on my computer's twitch scope test uh I'm going to go back and forth between docs and stuff like that to show you this is actually what I had to do uh I literally went into service now uh SDK and that's what I searched for and it was the first link so um going to the docs this is where I was and then went to uh install the service now SDK so what I had to do first was make sure you have not. Js installed uh and then it will install npm and the main thing you need to know about this is one it's required to do the SDK and then two you want to use these to control everything about the SDK and this has also opens the opportunity for you to do a lot of other stuff uh via your your own local computer um and and if you're wondering oh what what is even a an SDK it's very useful if you are used to doing any development in software development in a traditional fashion so for instance like if you've coded a website or if you coded an app and you did it strictly from like a script editor or an IDE like this um a lot of people not in service now will be used to doing development this way so it's even better to see that kind of process process and the SDK allows us to do that kind of work that kind of process uh directly in our editor instead of having to go to the service now interface feel more hacker man you know anyways so following the instructions uh I opened this uh folder in vs code specifically and then I opened a terminal so if you've never done that before it's up here uh view terminal and then after you've installed the npm and node.js then you could do this command npm uh install and then these two dashes usually means like an uh option or an additional parameter that you're trying to give it so I'm saying globally on my computer I want to install the service now SDK when you press enter it's going to do a bunch of stuff and it's going to find all the different files it needs it's going to figure out all the different things to make the SDK work and install those into your system so that you can start utilizing this uh software development kit uh so I'm doing this in real time so I'm going to wait for it to finish and you'll see it goes through a bunch of stuff okay so it's done so it says uh no errors um it did some warnings but that's all just application you can read through all this stuff it's um usually good to make sure you're knowing what's going on especially if it says warn or error we're going to take one step back and I'm actually going to show uh how to authenticate into the SDK so if you type in now SDK just by itself you'll get this huge list of uh information about the SDK uh they even have some SK art in here saying now SDK but then a bunch of the commands that you're able to do uh one of the main things you want to do first is authenticate to an instance and so I already have one so if I just say now SDK o it'll actually show you uh your available options for that uh and I can show I already created one so I'll say off list and show you that yeah I already have one for this my earo instance for the username earl. duk and I've given it an alias of earo so I can easily call this op authentication quickly by just saying earlier whenever I need to but if you didn't have one the way to to create a new one is that SD off save and if you ever are wondering what exactly is entailed in one of these uh commands for the SDK you can add this dashel to it and it'll describe you describe to you what it does exactly and uh like what optional parameters that you can add onto it um all that good stuff and so to create a new one um I can just say now SDK I'll follow the instructions for this one actually off uh save and then it wants the Alias um and I'll call this one able I'll say a t no ala a tutor because that's the username I'm going to add I'm going to connect it to and then the username is able dotor and the host is the instance itself so minus https uh earo do service- now. uh what else do I need to put in here anything that and I could put default equals false because I already have a different one but I'm just going to leave it out because I don't need it but if you're making one your first one you probably want to set default to true actually so uh that will help you later in your configuration but I'm going to leave this here and you'll see that it's going to prompt me like hey okay we know you are trying to log in as able tutor but we need the password for able tutor and I can type it out right now because you all can't see this and then I'll press enter and it's going to try to connect as able tutor and look so according to this it's saying I successfully did which is cool and if I now SDK off list again you'll see that I have two different uh aliases that I can use to log to run the SDK on a specific instance as a specific person um my default is earlier so I'm going to keep it like that one but now we can go back to creating an app so now SDK and I'm trying to remember all the commands for it what was it create okay so create project name scope name directory um and directory is optional if you're not in a folder already so let's create a new app now so how SDK uh create and it can't be capital letters it said so uh SN Dev program uh test oh no SN Dev program SDK test and then the app the scope name itself I'm going to call it the same thing SNF program SDK test and add the interactive parameter on there so it's trying to create it oh it wants the description I think I could have included that as a optional parameter right away live test of Washington SDK features build and reg build and register application on instance yes add a sample table to the application oh yeah sure cannot destructure property instance Ur all of this session as it is undefined I think I need to make sure I said what off okay so let's redo that live test of SDK and CLI in Washington and then the oth will be uh my early one the interactive part is trying to help me right away oh there it is okay so um it's because I forgot to leave off I left off what my uh what Alias I was trying to do this under so now what it's doing it's creating a bunch of stuff it's creating the scope in the instance it's creating the table in the instance and it's also giving creating all the files that I need to run the SDK uh in conjunction with my instance so it looks like it successfully created the instance so let's actually check it out I've never created a app via the SDK so that was my first time this is me doing it live actually so glad it worked okay so let's check out if that scope was created so let me refresh a little bit and oh there it is okay SN Dev program SDK test that's the one so so if I open up that um scope it should have made me a table it did it made me a Todo table for testing okay and to show you how the SDK works I'm going to start a business rooll uh and oh it created one actually okay so when I used the interactive one and it cre it created this business rle for for me which is cool um may look oh okay so it structured it already so this is interesting so when you use the interactive one and you tell it to build a table for you it actually creates uh the table and a sample business rule with the new SDK uh function calling built into it so um I'll come back to this to show you what it's h what's happening but notice that in my business rule uh if you know regular service now development if you go to the Advan tab you you would have a script in here and this is where you normally do stuff like uh current dot like to-do and or state and then set it to different things and manipulate the fields and all that kind of stuff so that's the stuff that would normally be there but instead if you're using the SDK you can just have this sitting there and then now if I go back into vs code um I can kind of talk through now what the structure is so if you've ever done any um Source control for service now you'll recognize some of this so if you go to metadata update you'll see all the files in your scope um and this one includes the uh here's the table and here's that cscript so if you don't know what a CIS script is that's what we are looking at oh where'd it go yeah this is a CIS script this is the business world that's what another that's what the business Rule table is called cisor Script so here it is and I can even further demon demonstrate that's the same file by uh going to that here and saying what's the CIS ID of it uh here's the unique identifier for it um ends with Delta Fox strot 9 Fox strot if I go here this one ends with Delta Fox shot 9 Fox shot so it's the same file and you'll notice that here right here the script is inputed in this XML F first of all it's all in XML files right right and then the script is loaded into this specific uh script field for the XML file surrounded by more wrappers and then it's not so and then it's not JavaScript so if it's not since it's in an XML file I don't have access to like intellisense or uh stuff like that but if I if I wanted to I could go in here and start adding um more script in here and start doing stuff in here but like nothing comes up when I do current if I set a Glide record like it doesn't have anything it doesn't know what to do with that um so it's not really pretty to edit in here but instead what it does is uh if you include this in your script Fields anywhere in service now that has a script field uh this is the structure for saying that I'm going to use my own file to run the SDK uh to write code in and so um in that folder where is it yeah so in the source folder uh in this sample app that automatically created some of these sample ones I have it already created my function. Js and if you notice in here it says hey I'm going to be re I'm going to pull in the file my function. Js and if I look at my function. Js uh there is a function called show status update and if I go back to service now it's saying hey I'm bringing in show status update from the file my function. Js and I'm running it using uh current. getet value as U one the first parameter and then previous dog value as the second parameter and now I'm in my own JS file and now since it's a Javascript file I can do whatever I want with it and be able to write JavaScript to my heart's content inside of this file and in fun fact you can actually do this in typescript files too so if you are knowledgeable about typescript or you want to switch to using typescript because it has different features that is helpful then you can actually write all of your script and typescript now too and when you compile and sync up your local VSS code to your instance it will rebuild all the scripts into proper ja JavaScript that can run on your instance and so let's talk if you've never done normal like node development or JavaScript development for on nodejs uh this might be a little bit new to understand but um I we'll walk through it right now so in these JavaScript files that you're using to kind of like inject your scripts into existing service Nel files uh you basically have this structure of import and then export um import is basically you're saying hey here's the different methods that I will want to use inside of my script uh and then export means I want this accessible to scripts inside service now uh and so if we walk back and that was like the overview now if we drill down a little bit more if this sounds PR scripted it's not it's absolutely not I'm just trying to try talk through it as I'm doing it like I said this is the first time I press the create function on the now SDK so I'm kind of ad libbing this live tell me how I'm doing um but the import part so notice that in this function I want to use gs. add info message um I can have I can this line cannot exist and I could still type out gs. add info message perfectly fine uh but my script won't know exactly what that is notice like I'm not getting indications of what I should be putting in here the intell sense isn't activating but the moment I un I put this back in did you see how GS turned red because it knows now like oh there's a bunch of stuff that you could do with gs. ADD um or any look all the GS stuff is loaded now all this stuff is part of the Glide system uh class for building JavaScript inside service now and uh now and that that existed before Washington DC like there was plugins for vs code that did Intel sens for service now and the previous SDK had um some similar functionality in that but the this whole idea of building scripts completely separated from your metadata files and having your these Fields just inject your scripts out of you're building is something new in Washington DC and that's what I'm showing right now yeah so this is saying hey I'm going to use GS from uh service now Glide and this is it actually autocompletes too so say I want to use Glide record in here if I just start typing Glide record there it is it autocompletes it because it knows where that is in your uh node modules folder and it'll include that there and now if I start building stuff like um uh inant gr equals new Glide record to the incident table and if I start doing stuff with incident you know it has all the stuff that you can do for Glide record built into here and I all I had to do was import it uh at the beginning of my field my script to know that I was going to use it but I'm going to go ahead and delete that and if I take that out uh so this is um what is this scripto by default uh it looks like it just adds a bunch of info messages and it runs after an update so I'm going to go ahead and Trigger that actually didn't I create a record oh yeah here it is so let me just have it update I'll trigger an update okay there there's the two um info messages and so if I'm in my SDK all I have to do is uh go in here and edit it to however I want I'm going to go ahead and say who who's chatting so Becca was the first one of the first chats and then banglish was the next chat so I'm going to add those names into there just to demo it and then uh it's saved on my local machine nothing's happening yet um until I build the build a a Deployable instance of this application and then upload it into service now and how to do that is oh I'll show you if I once I look so fetch pulls the application into my computer deploy okay so build and deploy where's build okay now SDK build and then now SDK deploy with the off of my Alias okay so to build the application it would just be now SDK build oh canot find package be sure you're running command and nna directory make sure you're on you're in the right folder so I'm going to close this folder real quick and I'm going to open uh because remember when I created the app it created I thought I was going to create all the the files in my root of twitch scope test but it actually created it in whatever example name that I gave it and I gave it the sndp - SDK D test and that's the root folder so I was open the previous so get to the folder that it created for you and then open that folder and then now I should be able to do it uh here's my new source file and then if I open Terminal back up I'm going to say now SDK build there we go now it's working all built it it's fast it was like one file anyway so that's why it's so fast uh and then now if I remember now SDK uh deploy under the Alias of earo and so now it's going to take the application that's on my the built application on my local system and it's going to upload it into my service now instance and then record some metrics and then it's done so that was pretty fast all right so to rehash uh so I took this uh demo function that it built for me and uh I edited the add info message to just say Becca and um for the first one and then benglish for the second one and uh I saved it and then when I go in and build and deploy that uh update or the entire application technically it's going to build it and then immediately deploy it because I combine them into one command if I go back to the instance and I trigger that business rule there it goes now it says Becca in front of the first one and bang on the second one so that means now that I have business rules and I have other fields that might um need updating or have script Fields schedule jobs or anything like that uh I can actually do all of that scripting inside of this uh SDK and I can do it in my own JavaScript files I can do it in my own typescript files and get them updated that's it that's how the SDK works it means I can do all the updates in here uh without actually doing it inside of the surface now interface uh this is really useful for what we're doing for the twitch stream in building our little uh bot presence uh monitor because that means I can work on this integration when I'm mostly in a different system I actually don't have to go into service now at all for a while and I can just do all the coding from here so if I stop this I'm going to um back out I'm going to jump into a different folder uh it's called early instance so I'm in a different folder now this is the folder I did to convert a previous uh app into the SDK and that one is was pretty straightforward too um I can show everybody real quick so all I did for this one instead was instead of saying now SDK create I said now SDK uh convert I believe right yeah convert and then I did similar thing I gave it a a scope name a scope name a package name uh if you're if you want to be explicit about the directory that's in you can actually add that as a um parameter all that's kind same stuff but similar to that and I just converted existing app and then it went in did what it needed to do to update it to being able to be compatible compatible with the SDK and I brought it in um and if you ever want to sync up your stuff make sure to just say now SDK Fetch and uh I'll actually do that right now okay so now my local system is up to date to what it is in service now and you'll see that I actually have a lot more stuff going on in my this app because we already started creating other stuff uh and then the last thing I made was Operation yeah okay so um I already did a little bit of the scaffolding for this so I moved the script that we made yesterday uh from uh I moved it out of here and into um a a new Javascript file that I have inside of this SDK now I can work on it via the SDK there it is so here it is so this is the exact script that you all probably remember from uh yesterday if you were watching that one hey thanks [Music] bye
https://www.youtube.com/watch?v=UYoMVq2_6ds