logo

NJP

What is Direct and Recordless Outbound REST in ServiceNow | 4MV4D | S01L11

Import · Oct 12, 2020 · video

[Music] in order to subscribe to my channel please click here or click here please share comment and like my videos and channel hello guys welcome back to sas web service now this is part of service now four minutes video for developers this is the next lesson of series of rest integration in service now in this lesson we will learn about direct and record less outbound rest message so you will learn what is direct outbound rest message and you will learn what is record-less outbound rest methods you can send a rest message from servicenow in two ways one by calling direct message racket in the script that means you can directly call the rest message record and another by calling endpoint with the script from the scratch from the instance so basically in direct rest methods you can send the outbound rest request from anywhere such as business rules script includes or schedule jobs and you can call the rest message racket created in the script so in order to connect in order to send the api call to the third party system you basically configure those information in the rest message record and then you call that rest message racket directly from the script and that's called direct outbound rest message and if i talk about another one that is racket less rest method now in record less rest method you can send outbound rest requests from anywhere however you have to create the rest message api from scratch and that is also without referring rest methods racket configuration that means the record which you create you do not have to refer it anywhere in the script now let's see how exactly you can define and call a rest message in my personal developer instance so basically we will create two types of script one is direct outbound rest message and another one is racket less so if i go to my personal developer instance over here so this was this one was secondary instance and if i talk about this one this is my primary instance now in our last session we created a rest methods record however we just created the rest methods record and and we did not call it basically we didn't did not we did not call it from anywhere now if i talk about it how exactly i can trigger it because we just did the testing we just clicked on that uh test button and we just did the testing that yes it is able to connect and it is able to fetching the racket but how exactly you can trigger the integration maybe on some condition how exactly you can do that so in that case you have to create something maybe you have to create some event so that it can initiate the integration it can call this direct rest message racket so as i mentioned we can do it in with basically two ways one direct and one is record less so we will start with the direct one first so in that case uh what i will do i will basically uh create a business rule in my primary one because we already created this rest methods racket so if i go back over here i already have that rest message racket the only thing i have to do i have to just trigger it i don't have to do anything so what i will do i will go to let's say business rules and here we will create a business rule so we have but but one more thing let me open this business room in a new tab over here because i will still require some details what details i will show you now one of the best thing if i talk about service now that you don't have to write these integration script i would say uh just the required details which are like dynamic details apart from that you don't have to think anything from scratch even for this direct message record as well servicenow will give you the ready template which you can use in your script how i how exactly i can use that i will show you quickly so if i come over here we are we have opened this new form of business tool so i will just mention maybe rest or maybe direct rest direct rest demo and i will select the table as let's say i will select incident or maybe let's say user user will be better yeah let's say user i think we always do it for incident let's say let's take another table for for demo so we will do it for user table and if i select over here so we have this user table and i will check this advanced check box and i will it says before let's say i will do it for update that means for every update this this should call the script and we will just see what script i'm talking about so i will come over here now as i mentioned servicenow gives you everything ready on your plate now what exactly is that so if you will go over here here you have this related link that's called preview script usage and that's a best i would say best feature guys if you're new to integration and you are integrating the application first time i would say this is very very helpful because you don't have to write scripts from scratch you just need to copy this so if i click over here you will see it will open up a pop-up for you so maybe i will just so here you can see it shows a pop-up that means it has taken the information from this rest message and it has provided this information automatically that means it has mentioned those information in this script automatically and you have to basically uh i would say focus one thing that is has mentioned try and catch that is part of the javascript so it is doing try and catch so i will just copy this okay i will just click again so i will just copy this i will go to my business rule and that's it i will paste it now here you can see it has already mentioned all the information like this integrate with another service now that that's the name of your rest message then it has taken the method automatically you don't have to mention it here are some other things like authentication details and all but that's already mentioned over here so you don't have to we will check that whether we are able to create the racket or maybe uh create the racket another system or maybe fetch it let's do one thing this time uh we will basically try to uh log the response because that's how you can you can do so what i will do then let me let me just go over here but i will also explain you each and every every line of code that what exactly it does but as of now i'm just showing you that i just need to copy it and one more thing i will do here i will do gs dot info now here i will basically provide uh the basically paste the basically a log that the message the whatever response i will get it from that instance so how exactly i get it from this response body so here it says execute it basically execute it sends the api call to that third-party system that means our secondary instance and get the data and then put it in response body which i can directly put it over here so let me just put it over here uh that's it and i will do like semicolon and maybe i will just do here so that i can just identify uh maybe sas now demo log because you will have lot of logs so i'm just putting it just to identify so we have put in gs dot info and that's it you are done and we will see whether it's working or not so i have mentioned here and this is for user table so what i will do i will go to user table now because that's what the business rule we have written and if i come over here i will just do sis user dot list one more thing i will open and that is log rackets so i will do logs as well so that you can see whether it is basically getting the response or not so i will put like this we have log we will sort it out and if i come over here let's say we have this apple tutor i will just edit this this title maybe test and now i will save it now if i will save it it should trigger an outbound call to that secondary instance with the same authentication details so we will see whether we are able to get it or not if i click on save so you can see i have saved it and now i will see the log if i'm getting the data from that instance or not and you can see here we are getting the data in xml because we didn't change it that means you don't have to i you can see i didn't have to provide any kind of authentication any kind of other details in the script it just copy paste and it's working and i can also get it in json format as well and if i come over here and i just change this one if i just application slash json and i save this that's set and let's say i i i would say test one two three and i save this racket again and you will see the format in json the response and if i refresh this so you can see now the response is in json and xml1 is at the bottom over here so these are the two different types of responses we got and that's how you can call any rest api and that's called direct so i can create i can do any operation as per my requirement with the help of this rest message but as of now this is direct rest methods now if i talk about all these all these line of code because these are the different components that you basically call so how exactly you do that basically if i talk about the rest message perspective you can see that i have copied it but it is not something that i have just copied is actually the script which which basically process the api call that means even if you don't copy and you want to create it from scratch you can do that so basically if i make it full screen and i just make it a little bit big so that you can understand what exactly uh these line of codes are so if i talk about i'm not i will not talk about this try and catch this is uh overall javascript but i will focus on these these these line of codes which are specific to this rest message integration so for any rest message integration when you put in service now basically you have to initiate you how exactly you have to initiate you have to create a rest message api object and that you have to put so you have to create a variable like here you can see where are you can it's up to you any variable you can take over here then after creating this object then you have to call its method however if i talk about direct one in direct one you already have a rest method racket in the system so what you have to do you have to provide the parameters so if you want to use the existing one you have to provide the parameters first of all which which rest message racket you want to use and what method for example if i change it to post or maybe any other method which is in that particular in that particular racket then i can put over here as well and then if i come little bit bottom here you have authentication details so i will show you one by one this whole line of code but when we will create it from scratch because that's what you will see so what i will do i will i will just come over here now next next basically main part is execute so how exactly it will send this api call because i don't know whether i have to execute it or not that's a method of this rest method v2 here is that execute so you have to call this method so you will when you will execute it it will basically return the response but how i will get the body of that response that's something you do with another method and that is response dot that means this variable where you store the where you mentioned this execute you have to do get body and by calling this function you can just you can just by this method you can just store the data into this response dot get body and whole whole json body or xml body will be stored in this variable and if i come little bit bottom then we have status code so if you remember we talked about the status code now how exactly you can check whether your integration was successful or not i did the testing but you can validate it in your scripting as well with the help of if condition and all that's something you can put with the help of logic now whatever logic you want to put you can put that as per your requirement so whatever response you are getting so let's say we have response dot get status code because in that get body we always get the status code as well so we have here over here response one not this one this one because it will return the whole response and here we will basically get the response code as well that is get status code that's another method for our rest this one for for rest method v2 uh api so if i come at the bottom again here we will store that value in http status it will definitely store 200 like we did this time and this is one the dynamic one the custom one which we just added and we have pasted basically uh push the whole response body i can also do for this log as well for example if i do let's say let me copy this i think you will understand better so let's say i do plus you will see that as of now i don't have anything over here after log but you will see that so if i click on save and i go to the our user and i just update it maybe i will delete this one and click on save you will see a difference so i have just updated it i go over here refresh the list and you will see this time i will get the sas now demo log 200 because i was able to paste basically get that status code and that's what you can get with the help of get status code and you can see the whole response in json format so this is how you basically create a direct message racket now we will create a record less rest message record that means we will not utilize we will not use the created rest message record we will create everything from scratch now if i talk about scratch as i mentioned i have to do everything from scratch you still don't need to if i talk about servicenow integration you still do not need to create the script from scratch and i am 100 sure about it you might have some doubt that how how how exactly i can do that yes that's one thing i can mention you cannot do it for other application but you will still be able to i would say uh get get an idea or maybe get the template how exactly you have to connect so how you will do that for that you have to go to your other instance so if i go over here now in this rest api explorer and that's the reason i really like these kind of features of servicenow that they give the power to the developers i don't have to think from scratch i i can just take some template and start focus on the main uh i would say main business logic not these kind of uh i would say scripting part where i have to remind i have to remember everything so what i will do if i come over here now here is the help now if you remember i mentioned about help script here you will find these help script that is also in different languages you have curl you have python you have ruby you have javascript you have perl you have powershell so if you are integrating for example if somebody uh has written any code in python and you want to integrate so i think in our in our previous session i have also used this i have shown the whole series in in the same series which i'm talking about there are some lessons in i think from from one to eight you will find how exactly you can use this rest api explorer and use these languages so i have created a script as well with python and connected with service now but for this case because this is for outbound what i will do i will just click on the servers now script that's it and i will just select it and i will copy this i have copied this i will go to my primary instance now i will come over here maybe i will go to the uh this business rule now here we we created basically direct one but now we will do it basically record less now i don't have any configuration ready i have to mention everything in the script how will i do that so let's start so maybe i will do i'll maybe do it from scratch i will not use this one so maybe i will just click on business rules and i will create a new one so create and this will be not for metrics because i think it was already selected and here i will mention record less rest demo that's what we are going to do i will select the table as same table says user and i will mention over here says underscore user where is our table and i go to here so here our table we have selected the cis user table i will click on advanced check box and here before update that's fine i will just do that before update and i will just maybe you can also mention maybe title changes title changes if title changes then only it should perform that action now i am going to click on advanced so whatever script we have copied i will just paste it over here now you can see that the best part is i do not have to basically put the end points and all everything is copied from there but you can see it says the username password admin admin because this is just a demo one it is not the actual password so i won't be able to show you the password because that's my personal developer instance password so you will not see but that's fine you will still see the username so what i will do here is if i go go from the beginning let's let's start from the beginning so i will make it full screen so that you see it properly so we will start from here here you can see i have not provided any kind of parameters so this is how create you create a rest api v2 rest message object so we'll create an object we will put basically create this request variable so we have this request object now and what we will do we will start with basically using the parameters that are using the methods so first we have to set the end point and that end point is basically because over there you already basically got all the values with the help of rest message racket but this is record less i don't have any racket i don't have to use anything so what i can do i have to start with set end point i have to set the end point first so i will put the whole end point you can see i have put in like this it also includes the parameter as well query parameter then i have to mention the http method that is again set so that you can send it to your third-party application so here i will use request dot set http method and here i have mentioned get you can also do post it's up to you what method or operation you want to perform in third party application and here we will provide the password so we have we already have username i will provide the password that's it and now we will have to provide we have to provide that what is the authentication way how you want to do that for that you have to select again set basic so i want to do this with basic authentication so if i select basic authentication you have to just put these variables username password that's it and if i come over next line you will see request header so you can also send custom header here you can see i have copied xml i can change it to json right here now the information which we were putting in the rest methods record you are just putting in the script that's a difference so if i come now little bit bottom here we have rare response again request dot x get a request dot execute and then it is automatically doing that gs.log response dot get body it is automatically doing that so you can you will see the whole response in the log so what i will do now maybe maybe i will i will just put over here i will put sas now demo lock and i will just click on save this is for record less and if i go to my user and i will just change the title maybe one two three and i click on save it will do a rest api call and if i go to log let's see what happens you will see i got the whole response and this time you can see we got this one this was the previous one where it says 200 and this is the new one and if you want to recheck it i can change the maybe i will add record less just to identify just to recognize that this is the one this this log is for this one so if i do that and if i go to my user again do a test and if i click on save it will trigger the call and if i come over here reload it we can see i got this as well record less and here is the whole result that's basically our whole body and that is also in json format so this is how you create record less and direct rest api the outbound rest method in servicenow to connect with any different kind of applications you want to integrate with servicenow

View original source

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