How to create a record in ServiceNow with the response from Outbound REST Message | 4MV4D | S01L14
[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 wealth service now this is part of servicenow four minutes video for developers and this is the next lesson of series of rest integration in service now in this lesson we will learn about create or update servicenow records with outbound rest response you will learn how to create or update a record in service now with the response from outbound rest message so in our last session we learned about how to parse a rest response now in this session we will focus and you will see a practical example that how exactly with that parsing of that record that responds how exactly can create or update any record in service now as of now the source is still our service now another servicenow instance however this particular way can be utilized with any kind of response json response you get from different systems this is my personal developer instance and this is the same primary instance and this one is our secondary instance now in our last session we learned about how to parse json response so if you remember we basically we were calling this rest message which is basically hitting the secondary instance we have over here and it is pulling uh the rackets which were created in this particular table in last two hours and if i go over here it is basically parsing the response which i'm getting from that instance and then it is also basically uh doing the logging as well so you can see it is printing uh the output in the log and as of now you can see we are just printing the asset tag the asset tag which is coming in this response body now as part of this video i'm going to create or update rackets that means i will be creating same asset in this instance as well how will i do that so let's go to here first so you can see we have these two rackets which were already created but i will create two new rackets the reason behind it because i already made a filter in my rest method for pulling rackets for last two hours but as of now these were created long back so that's the reason i will just click on this new button i will create two hardware assets here i will select the model category i can select maybe computer and then i will select model and here i can maybe select asus a53 and i can put the asset tag as maybe computer one two three four five or maybe zero zero one and i'm going to just save it so this is my first asset we created manually and then if i go to all assets again i will create another one and i will come over here select the hardware here i will select computer and model maybe i can select any other model maybe this one and i can give it as a tag as zero zero two that's it so we have created two new asset rackets so basically two assets are created in this instance that is our secondary instance now if i come over here if i run this job again it will definitely pull the data and it will do the logging but we don't want logging we want basically we want to create similar records in our this instance as well that means if i go to all assets table so these are all asset rackets now if you will see the difference so here we have two eight one seven rackets and if i come over here and i go to all assets here you can see we have two eight two zero that means it has three extra rackets overall we created i think four over here but it is still uh i think showing maybe one extra that's okay but overall if i talk about the choices perspective for example this computer this model category is already there if i talk about the racket perspective this model category we already selected in our secondary instance it's already there in primary instance as well and even even if i talk about uh let's say if i come over here if you have this model we have this model category even this model is available in our primary instance as well so overall you do not have to think about the racket whether that bracket is available or not but if i talk about any other third-party integration then you have to make sure specifically for reference fields because if you don't have that data then you definitely have to populate it maybe you have to create it it's something it's totally up to your requirement that how you want to populate those data but it's i think if it's a mandatory field then then you have to definitely put that data before so it's totally up to you how to handle how you exactly handle it so as of now what i will do so i'm just treating it as that i i do have these same reference rackets which i selected over here these are already there in this primary instance as well so i don't have to worry about uh the naming convention because i can just directly populate the name and it should be populated automatically so if i come over here even even society i think society won't match but i think we can populate it with the name that is something we might try so in order to create it what i can do let me make it full screen and make it a little bit big so that you can see the script now what i will do i will make it comment because i don't want to use this logging for now what i will do i will start with where gr equal to new glide record and here because we i have to create a record basically so in that case i will just copy this table and that is alm asset overall that's a name of the table so i can just put over here semicolon and i can do gr dot initialize that's how you create a new racket then i'm initializing over here now here you have to basically uh update the field values you have to populate the field values uh you and you and where exactly will get those values to to be populated from your json response so in that case i will do gr dot so let's say we have or maybe let's open one record so if i open this one so i have this display name so i just see display name and i come over here i will just put display underscore name and if i do gr dot i can not gr dot i just have to do like this copy this come over here now as of now we were printing this asset tag but i don't have to do that here it's a display name so i just need to do display underscore name that means it will populate the display name from the response body and for for one racket and overall we are already iterating it so you can see we are already basically looping the value so it is running the for loop for every every racket it will loop in the json body and print it over here so if i do for example let me do model this time and if i come over here and i copy this we have model and we have model category so in that case if i do model and model category let's copy this one put it over here i can do model semicolon and i can also do model underscore category and i can just paste like this and if i come over here model underscore category or maybe i can just copy from here because overall field names are same but if you're integrating with any third party application then you definitely have to put those field fields basically over here so then i can put asset tag so i'll do asset tag equal to and i can use the same one which we already printed last time so i will just do semicolon and now you can just mention insert that's it now this will create a new racket basically two rackets depend on the kind of responses you get because we created two rackets so it will and it will only fetch two rackets because it it got created in last two hours so and it will basically loop over here as part of the length we have in json response and then it will create racket for each each record we have in response body so in that case i will just save it so it is saved and overall it should basically create the rackets if i come over here what i have done basically i'm i'm matching the values so i'm putting the same value which which is which basically i'm getting from this response body so i have initialize insert i think we should be good so i can just click on execute now if i do that let's see it is done i have executed it and you can see here the racket is created computer002 and computer001 that's what we created over here so this is our primary instance and you can see our record is created and if i go to display name so you can see display name is also over here and even the asset tag what exactly basically value is missing now the value we are missing for model category and model the reason behind it we might be getting i think uh cis id if i if i'm not wrong we might we might be getting society from this particular instance this this one that's the reason uh it is it is not able to populate it now for that you have to make sure that you are getting the name maybe because society won't be same that's that's some one thing you have to remember so maybe you have to populate it uh with the name that is something you can do so maybe for example and i'm sure this is this is a reference field or maybe if i come over here and maybe i'll just do like this configure dictionary let's see if it's a choice field or it's a reference field so i think we can use the name as well that is that is still i would say uh fine so it will automatically populate it but this time because i think we are getting uh maybe maybe let's check quickly i think we can check it let's go back let's go back to our script here and we can print the logs again so if i remove this comment and i click on save now you will see that that it will create the rackets again so if i click on execute now you will see that it will create same rackets again you can see now how can you save this duplication so there are different ways you can save this duplication so maybe in in the same script this scheduled job which you have written that script execution which you are doing you can just mention maybe you can do a check in this table first whether same name asset is available or not mostly asset tag will always be different so maybe you can check as a tag if same asset tag is available rather than creation you can do the updation that's what you can do with the help of this this rest message now if i if i come over here so we have this four rackets and i come over here so we had this log enabled and i can just quickly go to logs to check whether what kind of data i'm getting so i come over here and i will just sort it so yeah you can see so if you will search if you will search for for example you search for [Music] model let's see what exactly we have so if i search for model you can see the model category isn't basically link the link is there and there is this id the value is basically cis id and that's the reason the reason behind it because we don't have same society if you will have the same society then definitely it would have populated the value but if it's a different society then it won't populate the value in order you know then rather than society you have to basically fetch name not not not the society you have to basically fetch the name of that particular model or model category but overall as you can see over here that i have been able to create the rackets this is how you can create or update the rackets but here you can see i have created four rackets as i mentioned you can still go over here and in here maybe you can do a quick check first so you can do the glide record and you can check whether the same asset tag is available or not if it's available then you you just do need to do update if it's not available then it can go to initialize part again that means this you can write this in the else part and it will create the racket and if it's not then you can just do gr dot update that's it same record if it matches the asset tag update the same same bracket that's how you can create or update record when you get the response from a third-party system as part of the json response you can just create or update rackets in service now
https://www.youtube.com/watch?v=FKyEWWP9Et0