ServiceNow Scripted REST APIs: Part 3 – Tools: Mockaroo
foreign welcome back in the previous video we looked at the application that we're going to use as the basis for our scripted rest API the vehicles application at the moment however that application that table doesn't contain any data and we all need demo data right and aren't you tired of creating demo data either manually or semi-manually so I thought as part of this series we'll just take a little detour and take a look at an application that I use to generate demo data for my applications it's called mockeroo so let's go ahead and create some demo data and then we'll see how we can import that data either via a spreadsheet or even better using an incoming integration and integration Hub it's real easy so let's get started so this is the home page of makuru you'll need to create an account there are different pricing plans that you can get but there is also a free account level what we're seeing here at the moment is the demo schema that is presented by the system itself but let's go ahead and create our new schema so by schema we just mean a table schema so where we need to define the fields and the values that we want to have in those fields so if I come here to create a new schema here what we'll do we'll just need to replace these default values into the values that we want to have so for example we need the make of the car and then for the the type of field here we've got all these different options here we've got different options for car details make model year Etc there's a whole Library here that you can filter and take a look at so for the first one we'll Select Car make and then we'll go ahead and select model and then we'll just skip ahead here and do everything real quick because you don't need to see all the different details for the different fields that I want to create but suffice to say that the fields that we are creating here are exactly the same as the ones that we've already got in our table schema in our vehicles application okay so now that we've finished creating our schema we can go ahead and Export that data so there are different file formats that you can use here such as Json or Excel and for our little demonstration here we'll just change the number of rows that we want to export to 10 I think with a free account you can export a maximum of 100 a thousand rows rather per export run and then we go ahead and download that data we download a spreadsheet and we can open it up and take a quick look at those 10 records that are created using that table schema and the type of fields that we selected so we can see here that we've got 10 records for all the fields that we Define and we've got the demo data for all the fields that we have specified note here that we only have an end date for one of those 10 because we specified in the schema itself that we didn't want to populate field values for every single record you can actually specify how many records of the percentage of records that you want to have populated with field values and the rest you can just leave us blank for our demonstration however here we won't go through the process of importing that spreadsheet because I'm sure most of you have done that before using import set tables instead we're going to use a better way we're going to actually create an API for our data that we have right here and connect to it from our servicenow instance and pull the data in that way automatically so the way we do that is we go and create an API in mokuru so you can see here it's already defaulted to the vehicles schema so you can Define different schemas here and how many records you want to generate every time you pull data in using that API you can also see the endpoint up the top there by default we don't have to do anything else click on create that's it we can then connect to this API using that API key that is part of our account so before we set up our data source I've already gone ahead and created a connection and credential alias in servicenow for our makuru vehicles application so if we come down here to the connection here you can see the connection URL is the endpoint that we just saw in mokuru so now if we come to our data sources here and create a new one we'll give this one a name mockery vehicles will provide the table label for the import set table which will be import vehicles the type here will need to be rest integration hub and then the format that we're going to get responses from that API back in will be Json so we'll need to select that as well the path for each row will be delineated with these two forward slashes so once you do select the rest integration Hub type in your data source you'll see this request action field appears so what we need to do is create a new request action and what this will do is open up the action designer in flow designer it's more or less been pre-configured we only have to provide a few other parameters to connect to our data source so here again we'll give it a name called get vehicles it will be contained in our vehicles application we'll provide a description and then click on submit so as you can see here we've got the foundation now for the connection that we're going to make to the data source to the mockeroo API we don't really need to do that much here we don't need to add any action steps here all we need to do is click on the rest step action step give it a name say that we're going to define the connection details using a connection Alias the one that we just looked at and then we'll go ahead and add the API key as part of the header so that we are authorized authenticated to connect to that API and that's it that's all we have to do so we just go ahead and save and publish that and then we can come back to our main servicenow interface select that request action and our data source is done okay that will connect to that API and pull that data okay what's the next step well like all new data sources we need to test load some records because at the moment we don't have an import set table so we can't do any field mapping yet we can't create a transform app so we'll just go ahead and test load those records and if we come here and open up one of these records we can see that that worked we've got that data we've connected to the API and we're just pulling in fresh demo data with every single core isn't that just fantastic no more manual creation of data for our applications for our demo data so now that we've test loaded those 20 records let's go ahead now and create our transform map again we'll give it a name transform Vehicles we'll specify the vehicles table as the target table and we'll just go ahead and click on Auto map matching fields and because I've made the field names in the API exactly the same as the field names that I've got in my vehicles application those nine fields are automatically mapped I don't have to go ahead and do any manual field mapping what I will do however is go ahead and change or set the coalesce for the VIN field the vehicle identification number because that is in actual fact the unique identification number for every vehicle on this planet so hopefully we can't go wrong by setting that as the coalesce field so we'll go ahead and do that I'm going to skip indexing here I will take care of that a little bit later but if you haven't already watched my videos earlier about indexing in servicenow take a look at them it is very important for the performance of your application and your instance as a whole another thing that we should do however is change the format for the date fields so we specified year month and date in our macaroo people schema so we just need to make sure that we use the same format here as well for when we import records otherwise we'll get errors so just to go ahead and do that for the start date and the end date so we'll come over here to application navigator and go to schedule Imports we'll go ahead and create a new record give it a name and when you do it this way that means you can just run this scheduled import her how often you like and just pull in new demo data as much as you like okay we're going to select the data source mockery vehicles now for the purpose of Simplicity and time I'm just going to run this as myself I'm actually a system administrator in this instance but this is a big No-No normally okay create a separate integration user with the respective roles or the roles that that user needs to perform this operation okay don't do it as a system administrator so we'll go ahead and save that and then we can just go and execute it and that's it okay we have now defined an API in mokuru that connects to our table schema and now that we can connect to it from servicenow using integration hub using that custom rest integration Hub action pulling that data into servicenow either as a scheduled job doing that automatically or if you want to execute it manually you can do that as well it is that simple okay there is no reason anymore to create demo data manually if we have about one of the records here you'll see here that the year has a comma after the two maybe you already know how we could fix that or at least what direction would you be going in if you said field attribute dictionary attribute you will be absolutely correct so what we'll do here we'll just right click on the field here come to configure dictionary and then come down to our attributes related list create a new record here do you know what the attribute is called starts with the letter F format okay so it's like format we select the value of none we save that and we can come back to our form here and we can see that the year is formatted well with no formatting exactly how it should be so that's it now we have our own vehicle demo data in servicenow in our table and now we can start the process of creating a web service to allow external clients and applications to connect to that data so stay tuned for that it's coming in the next video foreign
https://www.youtube.com/watch?v=m52m_XuqYwE