Integration between two ServiceNow instances | RestMessage | Basic Auth | Staging Table | Chapter 4
hi everyone this is the fourth video in the series of integrations and in this video i'm going to show you integration between two servicenow instances using authentication type as basic i will come back to the authentication types are using port or uwt in my future videos but let's focus on this one with basic auth for now and to start with the things i am going to first jump to the list message which i am going to use in my code so the use case which i am going to consider here is whenever an incident is created in the instance a corresponding incident is also created in the instance b okay so let's get started first of all to start with the things i need to have a web service in my instance b which i'm going to hit to create a record or if you are integrating directly with the incident table and not using a staging table in between then you can simply do that as well by creating records directly in the incident table but make sure your integration user has the required rules it might differ based on the implementation type i am going to show you the one with the staging table in place so i have already created a staging table in my instance b so this is my instance b and his the staging table that is my web service with all the fields in the incident table as well and this is the transform map i have set coalition id to 2 as collage and this is the transform map from source table to the target table and let's get started so i am back in my instance a i'll go to the rest message module come on [Music] let's click on new so let me give the name as demo underscore instance a and the end point for my instance b needs to come here [Music] i'm not going to select anything over here for now let's create a new record incident insert is the name and the message i'm going to use is post because i'm planning to create a new record in the instance b and [Music] table api url for my web service is api now table and as i already mentioned this is going to be basic and i have already created a user which is this one demo underscore basic is the using the card so we'll just pop up here and if i submit so this part is done let me save this record first and we'll move forward [Music] and this is my http http request here i can set certain headers like content type and the value is going to be json and i'm planning to send my data in json format and here i can pass the variables which i am planning to use for example i am planning to pass short description from here so it would look something like this [Music] next i want to pass description [Music] and third is the correlation id okay then let's save this card once again and i can also click on auto generate variables to test it out with some test values if this works out for me so i'm going to give a correlation ideas any dummy value for now description would be [Music] test to description short description is test shot and let's click on test so we'll come to know if this is going to work or not okay looks like some issue with the content type i have mentioned let's go back oh i missed one p in the application i'll click on test again user is not authenticated status failure required to provide auth information let's go back and see so let me go back to my instance b and see if let's reload this one first same password which i have already given to the basic profile that i have created and i am going to allow only web service access let's try it again okay so this works now and you can see here that i have received some response where i can also find this id of the incident that is created so if you guys are also planning to store the coalition id on the instance a then this is the place where you will have to fetch this id from the response and let's verify whether there is an incident created with this coalition id in the instance b [Music] yeah this is to one so this is the incident number this is the short description that i gave in my request and this is the description that i have given in my request so test execution works fine now let us see how i can make it work in the practical use case so what i'm going to do is let's go back first if you're not too good at scripting then you can simply copy paste the script and i'm going to tell you from where this is the area click on preview script usage and you can copy the entire code from here okay and just go to businesses so the table for my business advanced when i want this to be executed is depends on your use case if you're planning to do certain modifications after the api call happens then you can use async because things will carry on in the back end and once that happens you can take any action if this is a one-way call then you can simply do after insert so once your incident is inserted into instance a stable then only the api call will be triggered so for now i'm simply going to use async insert and i'll copy paste the script which i copied from there id from the current incident and the description next is short description so this part seems to be complete and i can simply save this record and we can now test it out whether a record will be created in the instance b once i create an incident in this instance um okay so once i save this record an api call should happen to instance b and an incident should be created over there with this as the coalition id i think there is one mistake in my code which i have written first let's fix that one so in the correlation id field i am passing current.coalitionality which is not correct correlation id for the instance b's incident should be the number for my current incident okay then now it's good now let's get back to the incident and if i save this incident record now i'm expecting that an incident would be created in the end b with this as the short description and this is the description all right so so here we are the incident is created with the same short description and description that i have given over there so this is how we can use a rest message to create incident in the incident instance b while doing an api call from the instance a using basic auth and in the upcoming videos i'm also going to show how we can achieve the same thing using uh token based authentications like oauth and jwt now there are a couple of other additional use cases which could be taken into account for example i am sending the data for one incident from instance a to instance b instance b has the correlation id but when i talk about instance a here the coalition id i have not saved when an api call was made so this is something which could also be taken into account and i have already told you how that can be saved from the response that i am receiving i could see the sys id of the incident in instance b which could be utilized when it comes to the coalition id all from the response itself there can be couple of other modifications done so that the response contains the incident number and if you're dealing directly with the incident table i think the number and this id would already be part of the response so there are numerous things that can be done so you guys can practice all along using those use cases and if there is any confusion you can let me know in the comment section and this use case was specific to the insert but but when we need to do an update that can be done using the same way like using the list message but it would depend whether you need to use post or patch depending on what kind of methods you have used to implement let's take into account the one which i have used using the staging table to update the incident record if you again send the post request that would also be fine patch method is not required because you are inserting the data in the staging table not directly in the incident table and the transform map which is created for the staging table and the connecting to your target table which is incident contains coalition id as the goalies field so no matter how many post calls you make based on correlation id if there is a change in data the incident at the other end would be updated and no new incident would be inserted but things change when you are not using the transform map or your staging table you are using the table api for incident table directly if you do multiple post calls then a new incident will be inserted so in that case the recommended method is to use patch because patch means you are sending an update on the existing record okay so let's take a look at that as well how it is going to work when we talk about the update and i am going to take into account a particular scenario when let's say the impact changes on an existing incident record so i will jump on to my guest message again so i'm going to mark it as post and we'll see whether multiple incidents are created in the instance be all the existing one is updated so this is my existing incident and then since b let's save this record and i am going to quickly copy the end point from here okay you can simply uh mention the content over here or if you only want to send specific fields because if you mention here this will be like a hard-coded content where all the fields you will have to mention which are about to update but you can also mention the same content part in your script where you will only specify those fields which are changing since in my use case i have only mentioned about the impact field i am mentioning it here all right this is fun night when somebody writes the code for you and your work becomes too easy to say yes new so this is going to be transit on update and again my table is incident advanced update so whenever the impact field changes i need to do this api [Music] since i don't want a new incident record to be inserted i also need to sit the coalition id okay fine let's save this and i am going to go back to my list message again copy incident update fine so let's go back to the incident which i created a moment ago this is the same incident that was created by me and if i change the impact this is the existing incident on instance b impact is low by default if i change this to high and save the card okay i am expecting that impact on the incident in instance b is also modified and it is modified indeed and there is no new incident created with the same description for description let's verify the same then see your number here is 396 and that is the same case here so this is how we can also send the data on update of the incident without using patch because i am using the staging table where i am using coalition ids colace field so we only need to make sure that when we are sending data even an update the coalition id field is not blank so that it does not create a new incident in the instance b and it updates the existing one but as i mentioned if you're not using the staging table you're inserting incidents directly into your incident table then you need to use the appropriate http methodologies like post when you are trying to create an infinite patch when you are updating an incident and that is the recommended approach as well if you are dealing directly with the tables perspective tables so thank you for watching and don't forget to subscribe
https://www.youtube.com/watch?v=j3BVJAueXLM