NOWCommunity Live Stream - Topical Deep Dive - Flow Designer Decision Trees
[Music] good morning good afternoon good evening wherever you are and whenever you are welcome to the community livestream for May 21st 2020 my name is Chuck Tomasi and I am here to share with you all kinds of ideas based on your posts in the community this is one of them and today I am wearing the dark green which means it's a topical deep dive day this is where we're going to get into a specific feature of flow designer I believe it was in Madrid or New York I don't remember which release exactly but it's called decision trees and he can make your life and other people's lives a lot easier so I'll get into that just a minute let me get out of the way remind you this is on YouTube at the URL you see over there so give that thing a like subscribe click the bell you know what to do when you're on there if you've gotten to come in certainly throw them in there we've got a wonderful running chat good morning to everybody good good day I should say I don't know what time it is where you are the thank you for joining me means a whole lot go ahead and subscribe to that we also have this on Twitch if you are so inclined to watch over there unfortunately I can't watch the comments on both at the same time so I'm watching YouTube thank you for everybody who's joining and of course the knowledge digital experience continues as we get into week three this is now on now week where we talk about different ways people are using the ServiceNow platform and applications in their organization so wonderful content if you haven't already been there go over to knowledge dot service.com everything from week one and week two is in the on demand section and if you missed a hands-on workshop check out now learning dot service now.com and you can find a lot of those workshops there and more content is coming out over the next few weeks so don't think that once you've been there and seen everything there is to see this is like an amusement park we're adding rides all the time there's new things to see I don't think we're tearing down the old rides either that just keeps getting bigger Park so one ticket price and it is free over to knowledge servicenow calm and have yourself a wonderful time there let me Oh forgot to mention the developer portal haven't mentioned that in a while go over to the developer portal and get your free personal developer is since connect with other people at meetups will get a little more detail on that the api's learning plans lots of great information don't forget this is your resource it seems like at least once a week at least many times more than once a week somebody says how can I get better at ServiceNow how can I start building applications how can I learn more about scripting this is the place developer done ServiceNow comm is where you want to go to expand your knowledge and go from admin to developer over your new food new to the platform you've come from a different platform or full-stack environment and you want to learn more this is the place developer debt service now comm and among the goodies we've got over there are of course meetups where you can go to what was it meat I lost the title meetup.com / Pro / service now def program there are what does that say 22 and a half thousand people like-minded people and I expect that to grow rapidly because a lot of these meetups are now virtual there's one coming up in Stockholm next week if you're in the right time zone you could attend I don't speak Swedish but it'll be interesting to see what happens at Meetup and there's more coming up in June so take a look at the calendar if there isn't one in your area reach out to us we'd love to help you start one and when we get past all of this shut-in stay at home lockdown stuff and we start to socialize and see people face to face again this is extremely valuable so look forward to seeing you there let's turn off the title and go to the community page actually I'm not gonna go to the community I'm gonna go to my developer site because we have a lot to cover today I am going to be talking about decision trees in flow designer and our story goes something like this I've got my employee table and our employees have started to track their points for experience okay whether it's you know I finished a course or I've completed a project but this is a fictitious scenario but you get the idea this could be customer loyalty points could be a lot of other things and the points are in bands so if you were thinking about customer loyalty points it might be bronze silver gold platinum something like that if you we're talking about employee experience so I'm going to go with novice intermediate expert wizard so we're going to make that up as we go so I've already got a flow built out in flow designer let me bring that up which decides when is it time if you've updated your record and the points change is it time to update the band and this would look very much how a developer might write it if the points is less than a thousand then we have a commenting here which is why it looks that way if the points is less than a thousand let's say done with that it updates the record and sets the band field come on there it is band to novice you can see that right there band is novice all right and it goes on like that else--if points is between a thousand and 10,000 you get the idea but this is fairly hard coded as soon as somebody says oh wait we're changing it which happens all the time you're there and there we know this it's called experience and they say oh it's no longer 10,000 it's 12,000 or it's 8,000 and you got to come into your flow and change that we're going to separate the decision-making from the flow and make it extendable so if somebody does change the conditions for each of these bands it doesn't matter to us so let's go and do that now the first thing we need is what's called an answer table an answer table let's go to studio this is where we pull the answers it could be an existing table it could be a new table that you create so what I'm going to do is say what are the definitions where can I find the answer to my band what am I going to put into that field in that field right now the field is a choice list so I need a value just some choice value that I can put in there so what I will do is create a new answer table create a table studio however you want to create a table this is add a very complex process right here I'm going to call it employee band all right it's not going to extend anything from anywhere I don't need a new menu let's not do that let's put it in the CLS menu I don't even need a mobile module for forget that now for columns all I really need is a name you do that say that is a string that'll be my display value and you know let's put a value since it's going to be related to a choice list let's just say choice you know even better let's make that ooh I got a good idea let's do this let's call name let's get rid of value I'm gonna try something here I haven't done this before let's make this a choice and I'm going to relate the choice to the employee table so that it pulls the same list all right and you know what else I like to do on these I like to make an active field which is a true/false then I can disable them put a reference qualifier some sort of filter on that to say I don't need these records anymore now don't display the ones that are inactive let's default that to true so that all new records come in is true very very simple table that's my answers let's go populate that so if I look on my CLS application now it's in no particular order so my new table will probably be at the top there's my employee bands let's leave that record and create this new record now name is going to be a choice I did click new very poorly but it has no choices so what I'm going to do is configure the dictionary I love this trick saves all kinds of time and maintenance later on go down here and click advanced view this is a bonus this was not in the original script that I had or thought process I shouldn't say none of this is really scripted and down here on choiceless specification you see how you have choice table now I can pick my CLS employee table Oh wrong table missed by one employee have to be able to spell this morning employee CLS 628 CLS 323 there's is and it knows out of all the choice wields of the two choice fields that are on here out of all the choice fields let's pick the band field it will get the choices and the display values and all that good stuff from that other table so I'm borrowing I'm referencing that set of choices now my field has this stuff on it yay okay so I'm going to create a novice record save I'm going to create an intermediate record insert and stay an expert record insert and stay I could even put some kind of order on here if I wanted but I don't need it I'm going to do wizard but I'm not going to do master yet I'm gonna save that one okay so I've got these four choices as you progress and you get more points now I need to make a decision table this is where the decision process will happen all right so we go to decision tables underneath system definition see right there like that little target thing and I've got three of them I come out of the box that are for change management and in here I can see they're read-only because they belong to global and I'm not in global but I've got an input one or more inputs and that will dictate how its represented on flow designer because that's where these are actually activated from and then the decisions underneath when do I hit each of these branches so when you look at this flow let me go back to the flow for a minute you developers out there doesn't this look kind of like it should be a switch or something else and it's like we're using one value but we're comparing it against multiple things very similar concept but even better so back on our decision table let's go make one of our own create new give it a name call this employee fans as I'm not very imaginative now I have to point it to my answer table this is where it says where are you going to get the answers for this and I will put employee employee band there's my employee band table again this this is any table in the system you don't have to create a new one you could use existing records you may have templates that you use for this you may have but there's no reference qualifier so you got to be careful if you point it to CMT BCI and throwing out the best idea but you could use si eyes as your answers to some other decision you could use this as a I don't know assignment rules if you wanted so it's it's it's kind of in a way like the data look-up tables but a little bit different for flow designer so let's save that so that we stay on this record and you'll notice I've got two new related lists the inputs what do I need I need the employees inputs so let's create a new input this is going to be of type string I think yeah that'll do it's just a choice field actually you know what it is a choice field let's put choice because that's what field type will be available to me the label will be no points is an integer silly me what am i passing in and I'm passing it in the points that an employee has and that in fact is an integer the label will be employee points column name is predetermined it prefixes it with a you why it does this in a skullcap I don't know but I'm going to leave it because I'm just not gonna have it is mandatory I can't do any decision-making without this input so keep it around there well you want this read only I don't know seems like kind of a crazy thing to make it input read only but we'll take care of that so that is my input it looks like a dictionary entry it feels like a dictionary entry it probably is a dictionary order haven't looked there's my input tada that is what flow designer will ask for now I get down to the meat of this what are the decision criteria for each of these bands so I am going to create a new decision here this is so simple you don't need to be a developer to do it which is great because then you can delegate it to somebody else let's say novice is going to be my first thing so I'll do it at order 100 I could make novice the default answer not bad if you can't figure out how many points the person has let's default this to novice could do that and that is going to be where the employee points it already knows the integer fields in here consists of one whole integer field and the operators you can use on an integer field less than greater than there's no string operations in here is less than you've got less than a thousand points you are a novice tada tough stuff huh let's go do the others real quick for intermediate and this label is how it's going to show up on that decision-making process in flow designer 2 so very important that you label these so that you understand them this would be the second thing in the list I don't want to put another default answer that wouldn't make sense is greater than or is 1000 because the other one went up to but not including a thousand and points is less than not keywords I missed points is less than 10,000 let's say okay you got to work hard to be the next level here two more let's do oh you know what I haven't been picking the answer record do you notice that okay we're gonna go back and pick that out let's do it this time next level was expert at 300 without an answer you don't get very far okay so employee points is greater than or is ten thousand and we'll cut this one off at 20,000 points is less than 20,000 so anything with a 20,000 now the answer record I forgot to point it at the answer writer this comes from the table that I just point notice that it looks read only but the magnifying glass is up this is a document field a document ID field it already knows the table why I would want to switch it I don't know because I've already defined the answer table but then I can look up the records in here I'm defining expert there's expert dun dun I noticed it was missing because I looked at this list down here and said answer empty ants are empty and you can't set document ID fields from the list so let's go back to novice and set that don't forget your answer record and I can actually just start typing because it's the display value put that in there save that record do the next one intermediate we've got one more to do after this and that is wizard so let's pick intermediate looks good update record update record yeah sorry about that girl huh what does he heads for field for the answer field is for forgetting and I do sometimes so let's do the last one wizard is currently anything greater than a twenty thousand before I forget let's set the answer field here wizard done and we'll make this from order four hundred we're points is greater than or is 20,000 okay you get more in the twenty thousand you are a wizard so I've got my things here the one thing I wish the developers had done by default is if I put the condition on the list to see what that is I wish they had made this readable there's a dictionary attribute it seems like I ever create a condition field without that attribute okay secret little sauce if you put readable in here it does you don't see the encoded query string like this with the up carrots and whatnot it will say and an or and instead of field names it will be display values it's much nicer so dictionary attribute on condition field readable equals true look for it I wish need done that they did not okay decision table created that's it again you can make this very easy for somebody else to maintain they say hey conditions have changed we'll get to that in just a little bit now let's go back to our flow and replace this ugliness I know it looks beautiful to some programmers but it's not and I'm going to write up about you know let's just tear it out I don't need it delete the if and everything else goes away if you go from the bottom up get it in one at a time there we are let's go and underneath flow logic there's this make a decision this is what's going to use the decision tree so we make a decision and we can give it a label it'll already have a label if I use this and there is our employee bands oh that was easy hey how do you want this to work first I do want to match all of them any of them that kind of thing I'm going to say the first one that matches wins cuz they are mutually exclusive at this point and I can include a default case here and otherwise notice when I click this when I would before I go further as soon as I decided what this table was or which decision table to use it pulled out those decision processes so there's novice intermediate expert wizard in the I specified and if I put otherwise on here it's got an otherwise handy again if you don't have a case this is like default in a switch for your developers out there you've got ABCD and well what if it's K okay K will default to something else maybe it's an error condition I don't have that right now because you're gonna have maybe okay maybe you could put in a negative number for the points but that's still less than a thousand and you would become a novice but I've got all my cases covered I don't need the otherwise in here anything else I do need in here well I need the employee points that's what's going to be posted so I've got my trigger record employee I've got points let's put that in there and that's it for my decision now what do I want to do in each one of these cases well it's pretty straightforward simple I'm going to do an update record same as before this is what was under each one of those if-else if-else and set the band to novice it is the exciting part I should have only gone with two cases because this is very repetitive at this point but I'll go as fast as I can update record dragging the employee record say hey state that state band I've been to too many things with the state field lately he has intermediate and again you could put any other flow actions on your sandesh like message congratulations you've been promoted that kind of thing doesn't matter to me update record print a PDF set up a certificate give up a give him a fifty dollar coupon to Amazon band is expert and wizard he's going to be my final update record for the moment we're imagining that that master is not in there that's gonna come along later because requirements change I just wanted to save you the hassle of doing it and is wizard I get them all okay now notice update employer record update employee record update employee record not very friendly if I were to do this in a production environment I would say band equals and all this maybe you're setting something else put it in those comments those little annotations are very helpful let's go test it out now I have a record for let's get my CL s employees up here I've got Chuck Craig and Jeremy Jeremy currently has zero points let's say he's done a whole bunch of work finished projects done whatever he's earned points community charity I don't know how you get points I you make up your own rules for this story and suddenly he's got 1200 points we better activate that so it's the latest version oh we're going to test we're ready to test so let us you know what let's just activate it I feel pretty brave at this let's activate it so that the if/else one is now out of the picture our new one with the fingers crossed throw the holy water whatever we're gonna do to this thing they're successfully activated we go 1200 save he should advanced-intermediate in a couple of seconds meanwhile I'll read the comments there's one execution field put some light on that place there is one execution field I'm gonna have to look for that where we going with execution field and why didn't this execute there goes right as I was getting nervous so he's been updated to intermediate by the decision tree is a decision table free or his license associated I'm not sure last I checked it was a new table and it wasn't in that exclusion I'm looking into that a little further if you've got any licensing questions I don't answer them here because licences are likely to change in this video will live on forever so check with your account team as of 2020 as of May 21st 2020 I believe that the does any new table like a decision table is going to be subject to license if you are licensed by table ok Licensing's licenses change as of 2020 the whole license program changed so you got to check with what are your license what does your license agreement look like talk to your account team because I can't answer that here I don't know your contract looks like where you are in that process it could be by users it could be by license it could be roles don't know okay so my safest answer talk to your account team there is one excuse it would be nice if decision tables could be used in place of rules on an order guide when deciding what items to include potentially potentially if you have to think about how that would work you could use the catalogue item as your answer table maybe think about that you can use any table as your answers so and you can hit multiples of those remember in the flow it said apply all that match what was it it was it was first decision that matches or run all decisions that match so you could finish I could potentially do that and add things to whatever it is now remember when you're in a decision excuse me when you're in an order guide there's rules that apply to which items are going to show up as well so this happens once the flow starts which is going to be connected to your respective items oh can you attach a flow to an order guide I haven't looked I'm done order guides in awhile my ITSM information is rusty okay so I've got this working looks like it's all fine and dandy until somebody says hey we're changing the point structure we want to update the decision table so that experts are now 10,000 to 25,000 well I don't need to come into my flow and change that oh and we're adding a new category called wizard which will twenty twenty five thousand and above like wow you just like totally messed me up for the first part all we have to do is go back to our decision table and add the new rules okay so let's first go to the answer table my fault let's go to the answer table and create a new answer so we have our employee band's new we're going to call this master submit dinging we now have a new level go back to the decision tables add our new band adjust the points on expert or wizard was it wizard so expert I got to read my notes so cuz I had this all planned out expert was going to go ten to twenty five wizard was twenty five and above okay before we get that master implemented so they say hey points are changing it's gonna be harder because we have so many people that are becoming wizards we got to raise the roof so let's do this let's go twenty five thousand there and we will go wizard is 25k and above now notice I did not touch the flow at this point watch what happens when Craig goes to let's go back to our Oh we'll pick on Jeremy Jeremy's done a whole bunch of more work he's now got twenty two thousand points that would have been enough to get him wizard status before where the cutoff was twenty K the bar has been raised to twenty five K so let's do that work for a little bit higher I worked for a little bit he's still an expert he's not a wizard yet because wizard has been moved I didn't touch the flow there's the important part that's the key takeaway for this whole thing is you segregated the decision-making process from the flow which makes it easier to adjust these when just and this is one of the more volatile things that you'll run into is this is one of my key tenants about building an application is make it data-driven there's the data okay the decision tree is the data pretty simple the bands are data you're not going into the flow you don't have to go back to dev you don't have to recertify all this stuff you're just changing data it's like putting people into different groups hey you don't go to dev to add a person to a group or add a role to a group or take somebody out and that doesn't happen that's just part of the normal order change so is this okay your change management processes may dictate that you test this on another instance to verify it but this is pretty low risk stuff it's data management it's not app configuration well I guess in a way it is app configuration but let's go on okay next requirement comes up we've got a new band we're going to call it master because everybody boughs down to the master right master will start at 25k and above so we need to update our wizard actually 100k wizard is going to stop at 100k because currently wizard has no upper bound let's go to our decision table let's take our employee bands and wizard has no upper band but it's going to we're now going to limit this that's greater than or is 20,000 and is less than 100,000 points get the right amount of digits in there and we need to make a new band let's make a new decision that anybody greater than that is now a wizard they are going to be at 500 the answer for that will come up with our answer table that we modified before not wizard master condition for that will be points is greater than 100,000 there we go make sure everything's still working over on the streaming machine so I've got these bands and I've put another one on the end so we've got a wizard watch what happens to flow designer I didn't even refresh this screen oh I guess I need to refresh the screen let's go back into employee points bands and it knows master hey master is one of the decisions it went sucked it all in now it doesn't do any action at this point but of course for you and me this is easy enough you go hey you made a band I got it what do you want to do with it oh let's do another update record because that's simple enough update record and we will grab the employee data pill set the band field oops I just wanted to call these bands something more interesting like Led Zeppelin done there we are and of course being a good developer future self will appreciate us when we say band equals master yi dun dun dun save activate and from whatever integration we've built Jeremy's getting more points for doing his wonderful work because he's such an awesome guy maybe for being on an episode of tech now he gets a million points that's starting to sound more like whose line is it anyway the points don't matter let's go back to our jeremy record which i had recently there he is and he's done a whole bunch of work he's got 100 and 1000 points and 100 and 1000 points save that did activate it I saved it I thought I activated it we're going to find out if he turns out that he's a wizard I forgot to activate it if it turns out to be a master then I remember this is happening asynchronously by the way it's happening in the background which is why you see it taking a few seconds if I wanted to change that I could go up to the trigger and say underneath Advanced Options this is as of Orlando run in background I could run it in the foreground but remember the more you run in the foreground like before and after business rules the longer it could take to return to control of the browser so the person may be saying it about what is taking so long I haven't tested this in the foreground I think that might be fun let's go do that just for let's see how responsive flow designer is to a quick change like this I don't know never did this before activate that I'm not even using the test button I'm feeling so brazen today and let's go give Craig some points so the cutoff was 1 10 25 and 100 so let's go back to our employee table Louie bans employees and we'll say Craig you've done a wonderful job you now have 12,000 points save and that's feeling a little long that wasn't too bad that wasn't too bad that was right on that borderline of what's taking so long why is the system so slow where users will start to think it's your fault and that service now sucks well no you got to process these things asynchronously in this case where it's something that appears on the screen I would consider running this in the foreground if it's triggering half a dozen flows you may want to run some of those in the background if it's something that does not appear on the screen its hat it's doing an integration or sending you sending something slack whatever if it's not something that has to happen right this second process in the back that's why defaults in the background so there's one other thing that I discovered just this morning before I was ready to roll the camera and that is a decision table API I go to the doc site and I'll include links to this in the show notes so don't worry about that and I say decision table API I was typing decision table and I noticed this came up and went what what is that it is an API that you can work with in your scripts your server-side scripts to get information out of there so you instantiate a new decision table API object thingy they call there's DT and their various methods yet all says go get all the decision tables for us it would be those for the employee bands the change management change minute or whatever those three of three others were that were around change and it would return you back look at this API crazy documentation we get all this wonderful information so just by saying go get all and then string a fight so we can read it the result comes back with here's all your inputs here's all your stuff here's all your inputs each other stuff this is this is one cold distinct answers it's got a lot of information this is the most the longest response payload I've seen on that doc page okay we've also got get answers for a specific decision ID so for us if we were to pass in the SIS ID of our employee bands decision table entry I would get back an object with what are some of the details around that I can map the inputs so when I say get decision I want a specific decision based on the inputs if I pass in the points you know inputs dot employee you underscore employee underscore points got to be that field name okay the field name is going to be the object looks like this I could pass in there's my inputs inputs was set here they're using an age and then here's the Society of the decision table that I'm going to use and you would get back an answer but get decisions is if you have multiple decisions that will match lots of great stuff in here the decision table API very handy if you want to use this outside a flow designer you could use this maybe that is a way to address that order guide scenario that you had before something to think about hadn't thought about that before so that is all I have for decision tables decision table API decision make a decision action in flow designer wonderful stuff way to segregate that decision-making process what are the conditions for each band to make it data-driven I love this because it is so it is data-driven and it makes it easier to maintain and isn't that what we want as developers and we want things that are easier to maintain things we can delegate and say hey sales department or customer service you go maintain those points you maintain the conditions I'm not going to be in that business but if you add a new band or a new loyalty or whatever let me know because I got to add that to the logic to update the record so that is all I have for today I am going to bid you fond farewell and there will be no show on Monday because it is a holiday here in the u.s. I am NOT going to hit up stupid early my day I consider it many days so the next one will be one week from today which would be Thursday May 28th and I'm still working on a topic for that no I'm not I have a topic and it is let me look let me look I'll give you a sneak peek at what it is I picked one out this morning our topic next week is going to be about client scripts based on a discussion we had in the community about client scripts I got a check I thought I answered this already but I'm going to double check for now it's going to be about client scripts but if I change my mind and wear different color shirt than orange you'll know something happened until then take care learn something share something be helpful and enjoy the rest of the knowledge 2020 digital experience over at knowledge debt service now calm take care bye [Music]
https://www.youtube.com/watch?v=s0gTr64LLbg