logo

NJP

ServiceNow Get started with Remote Table | ServiceNow Remote Table Chapter 2 | ServiceNow Demo

Import · Jun 27, 2022 · video

so let's start with the demo so as you can see on the screen this is my personal development instance and today we'll be creating an application okay for weather which i have explained in the theoretical session and what will be what we'll be doing we'll be using a remote table for the same we're using remote table we'll be calling an api which will be an external api to pull the data of the current weather condition of the location where user resides and then we'll create a report to showcase the statistics of the current temperature or you can say current information probably the temperature only so for this is for this particular tutorial we will be use we need external api right and in terms of external api so i will be using an open source epa which is where the api and this is the key epic is i have already created account for the same just to save the time and i will just copy this key out and if we go to the api explorer because we want to see the ap so there are a lot of eps but we will be using current current api which will give the current forecast of the uh of of the location of pink or whatever we will be you adding over here so we'll be giving zip code for us okay and we'll get the information based on that so let me give the key for the scene so this is the key json this seems to be fine i will keep it as long for now and i will go with show response so this is the expected response which we are which we are trying to get will not map every attribute so we will get we will try to get only few attributes like temperature in celsius temperature in fahrenheit wind miles per hour 10 kilo kilometers per hour and when degree if if required okay so let's go to the service now instead and see how we can put this data into a remote table on servicenow instance so i'll go come over here so in order to create a remote table so i've already created an application scoped application called update weather and we'll be doing all the all the coding in this particular application only so what you have to do in order to create a remote table the first step is to create a remote table so let's go let's type in the filter navigator you can type remote remote table and this is the module for remote tables so as you can see as i have mentioned in the theoretical solution also there are two components of it one is table and second is definition or we call that script okay so we will first create a table so i'll go and the creation of table is in this similarly how you create the regular table so we'll click on new will give it a name as where the update and will define few fields so how it can distinguish from the standard table so we have the checkbox right importable defined that this particular table is a reboot table okay so [Music] and i will give it a name as demo weather update we'll go to the columns and i'll be taking only few columns into consideration and in order to get in order to have a consistent structure so i will follow the same naming convention what is followed on the epa side okay so let's look into the few attributes so the first attribute which we'll be taking is um name okay with city because we will be providing zip code right so we need a name so i will take the first attribute as name and i will give it as name column name i will paste it this so back in name i'm putting in sync with the epa uh with the name which we are getting from the epa so i give the column time will keep it as string only for all the fields so this is done one attribute the second attribute what i want to take is so second attribute what we'll be taking is temperature in celsius so let's take that up so i will give temp in cs we'll give this name then the next attribute what let's take temperature in fahrenheit also so i will give them and our knight this should be capital and i'll give just f the way they have given and here also i will make it c only so temp in f i'll give it a name temper then what else we want to pull so the next attribute which i'll be putting is [Music] winds in miles per hour when speed and i will care in my only the other attribute which i want to take is what wind action let's take the wind action and direction i'll give it as wind i and the last attribute which we'll be taking into consideration is humidity so you can you can map as many attributes as you want but i for for the demo purpose i will just take this much of attribute humidity i will give the same name why i am giving the same name will come to know when we proceed in the tutorial so this is all i think one two three four five six six attributes is more than enough for this tutorial so now i will save it out and it will create our remote table so it got saved we have created six attribute okay and as we will be taking the current current standards only currently a temperature and all so we are expecting only one record in the remote table based on the logged in user so this is done so we have created a remote table now before jumping to the definition we have to call that api right so the best method to call the any apis into servicenow instance is to create a rest message so let's create a rest message for the same so i'll go to rest message and we will create a rest message called we'll give the same name demo weather update okay and endpoint in endpoint will give the endpoint which we have over here it will have some attributes okay query parameters which will be defining at the latter state so the base url for us is unlike this this all others are like query parameters so this is the base url so we'll just take this and save it out it doesn't require any authentic you don't need to define any authentication type because we'll be defining a key for the same now as you can see the get api automatically created so we'll open the get api and [Music] i will just paste the entire url over here now we want key right so the key will be the first attribute right so what we'll be doing will be creating a key for the same so it's key and then this is the second attribute here we'll be punishing the zip code i will give zip code and apik will be like api key okay save it out and we will auto generate variables will do auto generate variables sorry i missed to add dollar over here that's why the variables didn't get generated so let's add dollar so the first dollar we have to add over here it will be dollar key dollar zip code and the third one is the dollar api key that's just so much okay and now we don't want to write any any other information we'll save it out and then we'll click on auto generate variables to generate the variables which we have defined the dynamic parameters we can call it so i will do alternate variables and let's see so it created three variables okay api key key and zip code now let's try to pass some information to the scene so i will give the zip code for alabama just to just to test this api so zip code for alabama i have given then key sorry what and did something wrong okay eq this is a key this we don't require okay so we'll not pass anything in that so it will be [Music] know only i will just update it to no we can pass the attribute as no not an issue so let's do that only so i passed this value which is here i have to pass the zip code three five zero zero four which is for alabama now the test value here i will pass no which is nothing but aqi sorry here is defined and now the last thing we which we have to pass is this key so we will take the key i have just copied it from the previous screen so i will just take it up i will just paste it out in the key okay and now once this is done let's test the api if we are getting the positive response so l host may not be none so we have provided the values and now let's run the api so if i run if i do test so it give 200 and we got the entire information which we are expecting it's for alabama right and we got the entire information perfect now we have this api ready so what we will do we want to utilize the scene in our code to get to extract the information in the remote table definition so you can do that we'll just open this rest apa a rest message and we will do preview script usage so it will generate the script for us right and we will utilize the same script in our remote table so i will just copy this out the entire script okay from start till end close it out and let's go to our remote table again so i will tell you type remote table and now we will be going for the definitions for the same so this is a remotable definition i will open new and now we'll give it a name called demo weather update okay update and this particular we will give the table as a state weather because we want to select the remote table over here okay and here they have servicenow has provided really a really good documentation how exactly it should work so what exactly we have to do we have to just call the api and then we have to create an object of the information which we extracted from the external source and we have to just post it to as an address api okay we underscore table dot addrew okay so let's do that we only so i will you can go through it there are there are a lot of helper text given over here okay so i will not just go through it i will just add my comment okay i'll give weather formation extraction code and i'll paste my code over here whatever we got from the rest message so here we are this right right right and i will remove this other part part out okay and now we will change this attribute so key is already defined eq is there and zip code so zip code i want dynamic based on the user so i will define a function an internal function is virtually variable get user code okay equal to function i'll just do it pretty quickly and and here will be variable gr gi user equal to equal to new client record record i will be requiring to space user table then we'll do ci user dot get and what we want to get like here so we will be doing cat and yeah this is user and here we will give the session usage dot get user id okay and once we got get the object for the same now what we have to do we have to find the zip code so if we return gr user dot get value of what we want for zip and and will be this will return the zip code so we'll give gets zip code for locked end user so this part is done now we got the user we got the key defined over here okay and we'll replace this with that zip code let's get zip code done and here we'll get the response if execute response status code so we can give after this if http http status is equal to equal to 200 that means it's success then only will be creating an object right so if it's success then what we'll be doing will create a variable row object this is where we are defining the structure for the object which we want to push to the remote table so equal to variable row object equal to i will define adjacent in json i will define the same attribute which was defined on the table okay so we will will take attributes from there so what all we have added that's why i keep the consistent name so that i don't have to mess around between the variable names so it's name colon and here what we'll be doing here response right so i'll just convert into json response so let's do that also so variable response body json equal to because i have seen i have tried this api and it gives the output in a string format so that's why i'm doing this so it will be json dot path and in this will be passing response body okay so name equal to response body dot name then let's look into the next attribute so the name is done what is the next attribute so name is coming under location so we have to do location.name this you have to think carefully into the mapping location.name and the next attribute which we have in our list was temperature c right so which is in current object right so we have to do temperature see it will be colon response body dot current dot temperature c in this similar way we have temperature f right so let's do that also so temperature f will be temperature f then the next attribute we have totally of six attributes right so the next one was the phenomena wind meters per right so let's do that also so we can do [Music] this golden response body dot but was it it was outside only okay so not an issue then we had humidity when direction was one so let's take this attribute also in the similar way i will just copy this up two times so win the action and the last one was humidity okay it's not colon it's comma because we are defining json over here so now we have defined and we have created an object also now what we have to just do we have to just push this particular object row object to the remote table and how we can do that we can do it using this particular we table one so yeah if it's getting started here we'll give semicolon for this and if after the object get created we have to do i will just copy this out from here vtable dot add row and this add row we'll just put to object and this is done so basically what we are done we created a remote table first then we created it and we defined the columns on the same which we want to map from the external source then we created a rest message to extract the information to extract the data of response from the external entity or from the external api then now we have we want to bind this rest message response to the report table and that is done by the remote table definition so what we did we put the script the same script in the remote table definition and now after creating object we are just pushing that object to v table which you call as a remote table also okay and i will save this out so this is all done from our site okay now ideally in ideal scenario it should work so let's go and just go to the demo demo weather update okay and we'll go to the weather updates and let's see if we are getting the dot data or not so it's like read operation on this user table from script was granted so one mistake why the data is not reflecting one mistake we have done is we have used response body and we have to use the response body json right because it's a string field so let's replace this out so that will get the object we will save it again and let's see now so i have saved it out now let's go to the remote table and see if the data is getting reflected so we'll go to [Music] weather updates and now you can see we got the data for pine burst bluff okay it has temperature we got few attributes rank few attributes humidity wind wind speed let's look into that also so i think it's coming into something which we missed so humidity and all is coming under under current only okay i missed this so let's do this modification also so we have to do current dot current dot okay if i save this now ideally it should work so if we go over here back over here if i refresh it out so now we got the entire attributes okay fine bulb and this so we have taken the system user right which is fastest user table okay uh which has admin account so if i go to says user dot list and if i now change the location from [Music] bind bull to arizona okay so i will just go so it should automatically reflect the data on the remote table also so i will go over here i will open this admin record and i will just change the zip code okay and if i save this out so now if i refresh this so now you should be able to see the updated data you don't have to do anything so you can see it got changed to arizona phoenix now okay so every time you refresh the data okay every time you want to refresh the data you just refresh the page you just refresh the form or whenever you return back to this list view it will show you the latest data okay based on the code which you have defined on the remote table definition okay now if you want to cache the data now as i told you every time you replace the data it will show you the latest the new set of entities right if you want to carry this data out how you can cache this data so you can catch the data using an attribute on the remote table so if i if i go over here if i do the configure form layout so there is one attribute for caching multiple attributes again not one so you can see these attributes called cache dt and cache strategic class so you have to set this detail so if i go over here okay and you can pull this information i will just ttl cash strategy cash level right and i will save this out so you can see this information now in this particular tab i've just and yeah whatever if you define 300 this is in millisecond if you define 300 then your data will get cached for five minutes okay in the similar way you can catch the data okay so this is all for remote table okay hope you like this session and you got the clear understanding how exactly the remote table can be used to extract the data from any applications okay from external application you can use remote table whenever you want to get the data into service now but you don't want to store that data into servicenow right for example this weather application you don't want to store the weather information for each and every uses right you want it on a dynamic basis so it will act dynamically based on this remote table now you can create report dashboard whatever set whatever you want on top of this remote table

View original source

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