Episode 25 - Complex Objects in ServiceNow Flow Designer
good morning Ron and welcome to the with dr. sky to service now episode number 25 today we're going to talk a little bit more about integration up our last episode was about the XML parser and we did touch complex objects in there but I wanted to share a little bit more about it and how they work so today we're going to take a look at those and I actually added some more things like we're going to take a quick look at what you can do with connection and credential alias and the REST API Explorer for example just to show you how to to get some stuff done with that and what you can actually do with it being record in your fleece of course for those who don't know me my name is coral and fish take a day with dr. being playing around with ServiceNow for a couple of years now I think we're fine I guess before that I've been doing most of the stuff you can do an ID everything from sitting the service desk to be a system manager I to processes yeah you name it then I got into touch with ServiceNow as a customer in 2014 I went over to partner and now working at ServiceNow internally I said I've seen your application developer I guess that's about me mostly hopefully known me receive my other videos so if you like to get in touch with me you just feel free to I've think this is the right way to hit on the contact details and picture here also wrote the book I know I've been nagging about it for my videos but if you liked it and feel free to go to Amazon just search ServiceNow will pop up I'll try I have tried to write down most of the knowledge I have come up with over the years and trying to help you not do the same mistakes I did or scratch your head and wondering how does this work but enough about that today short again now let's take a look at the complex objects which is new how dare you does they work take a look at the connection and and a little bit how rest cults work in integration hub and in this case I'm just going to call my own instance so I'm just going to show you the REST API Explorer if you don't know about that one to see how you can test your own API rights as well so let's skip the the PowerPoint get rid of that so first of all we're talking about integration out we need to start the flow designer so let's get that one up I will already start it you get it by just talking flow you have to flow to sign up here hopefully you're all familiar with it I think it came around in was it Kingston or London up time flies when you have more fun I guess so - sure it is I have actually built two custom actions and that is basically where you will use these complex objects and let's go for the first one so let's see what our complex objects everywhere when you can do and create an input or an output you can build these complex outputs and basically what they actually give you is that you can have a variable let's call it test one and now if you take array you can see that you can actually now have an array of for example objects or boolean's whatever but by using this and especially in the outputs that means that later on in the flow you can actually use that output in like a for each loop and all those kind of cool stuff that was used in flows which you haven't been able to do before and of course you can build a lot more complex nestled or because as well you can have an array I'm just going to show you and in that array we have an object called test and in that object will have field one you can see my imagination is great then we can have field - and you can seek and of course change this field might also be an array of objects for example and then you can be deeper and deeper nestled pairs - to actually use this functionality but what I've been clicking around here now is actually in the inputs we do like that and I'm not going to have anything here so let's just delete those so in this base for show-and-tell I just look up some records in this case I'll say finally users in the HR department and give me for them then I have a script step and this is where the fun starts so before you start doing the code I will recommend building the object down here as an output first because when you're using the script you will need or use the the name of the different variables in your script as well so it's good to have those defined first then start using them so what do I do in the script first of all you can see from my lookup records I have the records in this and data so I have an input variable script - says that that data should go into this variable then since our complex data is an area of objects I create the variable called users and in this case I use the same just easier to understand where I should go then I just use a variable that can increase and then I start looping through the records that I got from the luca and here you can see i just use input use records dot next just like a normal fly query and then of course for each record i go through I need to have an object just like here so I define this one and then I use the same names here as I'm the object in here so first name I fit the first name from user last name same thing and force issues or I just get assist you sir from Asus ID from the user then we have the e and push data object because now we're done with that objects we push that internet right and then we'll live through the next one when we're done I say that this object output that users equals users meaning that herida that created from the start up here let me just turn off my outlooks won't be popping up the whole time so now we have actually created that as an output in terminal in the action but we would like to use it in the flow as well so we need to create the outputs as well and just to show you from the scratch let's do like this here we go where is my mouth area so lets the stood out a way that didn't tell you because I still know what I would like to do so let's go from the scratch you can see me creating and the first one you like to be and before I choose are always selecting labels so we call that one users and we like to be an array of objects then we call that a bit user and inside that object we would like to have first name and this is the labels that you will see in the data later on in the flow as well which can be good to know we want to have last name and we would like to have society and let's see how did I spell that to see someone yeah that's right oh come on stuff I should be don't really know if this is needed but I always make sure it exactly the same what I like to go down thank you so we have first name false name huh this is how it goes we should change stuff that already works so first name last name since our deals small letters first name last message so that's great now if you build even more complex objects and you would like to have the same object on the output you don't really want to ream create all this manual ways what you can do is you can click nothing that one on this one and save as template by doing that and to name or tone it down I had this one with a do it users and what's good to notice when I hit this save as template it will take a copy of the structure of the complex object as it is right now so if I hit save and I later on and I feel remove for something like that it will not leave become and copied over to the template again so that's a like a snapshot how it looks like when you click the save as template so make sure that you have the complex top it set up right how you want it before you start messing around with then us go to the output and as you might notice you have two different views or versions of this hands out but you have edit and you have we define what value should go in here so let's hit edit and let's trash this once you can see when I created from start you hit create output yeah I always do like this so I hate users and it should be an area objects and by doing that let's see if I can click on the right arrow here we go so now we have structure should create manually or from a templates directly start from template and here you can see all the templates that I have so I'll select version two that's the one that we made and then you can see it fills in the rest of it now we have defined those or hit exit now I only need to say that what data should end up here and that is this one so I'll just drag and drop that one now let's test and see if it works or hit test and we look at the steps we can see that we got we got some users got the right user records and error object if you just glance at it you can see last name it seemed to work so let's let's test this out with a float and I know start from scratch instead of taking use of my pre-built ones let's just back up I guess hey episode 25 users come on meet you as well unless you have to do like that for fun and I'll just take whatever trigger won't find my action I think it was episode there we go what is the action and this one is nice all just its save what you can do when you're building these kind of actions is that the don't really need to publish them to be able to use them in the flows for testing what you need to make sure is that if you click on the options here configurations make sure that you have this one slider to write that means that you can see also draft actions which is quite good so I'll just go feed episode 25 complex objects now you can see we have the naming that we had before this is what we get back and what do we want to do those let's just do that is done and then we'll take our for each and we like to loop through our users that we get back and then just just make something's we can show that it works let's create an incident where we put the color and we have for each sis ID in the color and you say that another official I hate my mag nation not that good my name is what full last name as well I'll hit done let's hit test run take of you seems complete you can see that we can look through all of those and four or five you can see that open let's do like this is easier pray that on today and never have those four you can see the color matches and you can see the last names so that is a good way to actually use complex objects in gaming to do so hopefully have better examples or use cases them not mine now for the last part let's take a quick look off [Music] don't care about those and just going to show you about rest calls the connection alias and stuff like that so in integration up when you want to do a rest call you can use something called connecting alias that means that you can basically define all the stuff in the connect and connection alias and connections and then when you move your flow to like test a prod it actually knows which connect unless it's you're supposed to use and in that connection alias you have like the base URL the credentials and stuff like that but because normally you might have different end points on test on dev and prop and you don't actually want to manually go in and edit that in the flow of the movie to test so what you do is that you create these connection and in credential ideas just put a reference here that this is the one I'm going to use then one time you only create those connections on the different instances and then it will know which base rails you'll use now and and so on and to show you you just hit connection you can see there are a few already out of the box depending of course it's folks you're having stuff like that so in distress call and we're actually just calling myself my only instance so I just call this one oonh instance you can see that you can have both connection crashes or if you have the same connection on all places you can have only credentials if you want another thing that's nice to know is about to read for policy which is new in New York as well which means that if you get some error back when you do the rest code you can actually define here how it should retry and you don't need to build that man manually every time in each flow you can actually build it here and then reuse it so after hit save you get the connections down here you can just click new which I have done and then you will pop up in here the credentials will be empty because you haven't created them this one is just a link to your connection areas and what it needs is to find it ok what's the base URL for this connection so if this has been correct it might mean like this and when I created this one on test it might be in like that and so on and I just need to define this one for the current roles you just look it up if you don't have anything you speak new define what kind of credentials is it that the endpoint has in this case I used basic identification just filled in the username password hit submit and then just link it to this record instead and then it's up and running and you can use it which is really good then as you might see in you have the base rel but you need for example to know the resource tab where I'm going to to hit the endpoint and since this is my own instance I'm going to you have a really good pay Explorer to look and test rate guys just tie REST API Explorer from here you have a few choices on the left if you have different scopes I'm going to use the now scope because I'm going to use the table API which is built-in pretty much for every table define what do you want to do we like to retrieve records many records you'd like to read one record create a record and so on depending on what issues looks a little bit different here but we would like to retrieve a couple records just like we did with the lookup action in the other floor let me show you just like this one we will do the same thing almost we're just going to fetch insolence instead but with the rest a Perico so I'll just say okay I would like to go into the instant table and then you have a couple of parameters you can't define you have a really good descriptions mostly has to show you for example active equals true let's have that as a filter since we're using complex object would be nice to have more than one so I'll just say 10 and then looking pretty much you'll say okay let's test this one out we got back okay if you scroll down you can see here is the resolved and then it looks good we got 10 different incidents from our instance now for a resource path if I scroll up I get URL you can see this is the base and then we have the resource pack here then we can see that we have two parameters which define earlier sispann query and system limit so what I have done yes I just you can see a copy the rest of URL select a gift and then just filled in the two different parameters just as we did and resource in this case I selected only five I said that yeah I'd like to use the the retry policy for this one so I checked that one and then we're good to go so now we know that the response back ends up in the response body as a string default it's a JSON objects we get the string apart so let's add a script step since we don't have a jsonparser yet only have the XML parser so this is what I've done I just name that the input variable response body should be the response body then I convert it into JSON object and as you can see I pretty much do the same thing as the another script so I know that the result and if you don't really know how it looks like you can go back to respond so you can see the okay here is the object and it starts with an array and in that array we have object so I get accomplished of it back and I also know that the result is an array of objects and I would like to look through them to get to each instant that I got so these are pretty much says to go through all in the instance that I got back and I create an object I say that the number should be the number in death specific object when I look true same with the CID and then I push it into that one into the array which I created over here and you can see it's pretty much the same structure with this one as in the old one and the same goes with outputs as well if I just go back click Edit you can see it looks just like it as well good to know is that if you don't have wide enough on the browser it might look like this and you can see that some icons is actually missing and I hope they'll fix that so you don't need to do that to actually see them I noticed that sometime when I moved it too small I don't even have the plus sign which can be kind of annoying or is just looking in time I've I know there should be some icons but you can't really find them which is also very annoying so pretty similar let's just show you the rest up and if you look on a flow I can show you that flow and it didn't seem to have been safe so let's build it them just doing the same stuff asked earlier older than 25 rest call always fun to make sure that they actually works what they are built I guess for each you can see we have the instance of rare I'll just drag them in and then I'll just create another incident for fun great record something this short description copy of incidence just pulling the number yeah we're done let's hit test it run and let's go back to incidents list and now you can see we have a nice 5 in sense being a copy off the other numbers we actually fit so this is how the complex up it works and before I let you go I'm just going to show one more thing and that's about the templates as you might noticed when I in complex objects and hit save still like that you always click on the wrong one you can save a template but you can't really find a place to just like deactivate to removal and if you make something wrong you would like to make a new template when you go back later on you will have a pretty large list here with templates of isn't even in use perhaps anymore and I don't know if there is that I have missed it I couldn't find any UI where you can actually edit and change these ones but of course there is a table for this so what I did was went to tables and yes guessed that it would probably have something with flow to do and when I scroll down let's see if I'm blind no it's not there you go flow design or complex or Wix templates could have to shorten a breath but yeah it works and you can see the table names is how flow designer SEO template so if I go into that list here are my templates and you can even see that I if I change this one it's just so episode 24 let's go back to the floor it's there and let's go here and let's change it to false now I don't think it's this fast is probably already loaded but if I wonder if this is good enough let's test it I didn't do that earlier yeah there you go now it's done so that's the place where you administrate right now your your templates as well so you have a table called flow design accomplished topic templates and you have a nice table name like this as well so that's about it about complex objects I hope you helps you a lot and you start building those right away so Sierra
https://www.youtube.com/watch?v=Hta-b1bMO7Q