Monitoring Variables on a RITM
welcome to inside the barrel it's been a couple weeks since our last recording so john and i thought we'd do a special one for you and invite nate as a guest and i'll give nate a little introduction about himself shortly but essentially for if this is your first video with us then essentially what we do is we talk about consulting life inside of cask and how we solve problems and try to get into technical things so that you don't have to do it alone so welcome back john well thank you you have a good heart you have a good holiday i had a good one yeah i mean i currently live in portugal now so i know so they don't celebrate thanksgiving here apparently uh wow go figure well you should make it a thing yeah yeah i was telling all my friends that like columbus you know brought over german beer and there was more beer than people so i was trying to like get them more involved so what you're saying is everyone drinks a lot in portugal yeah yeah why it's a big deal here well it looks like you still have some pictures to get hung there so you're not quite moved in yet huh yeah uh totally it's still a work in progress um awesome cool snake if you want to give a little intro about yourself and then tell us what we're talking about uh so uh nate weldon um one of the uh senior directors here at cask i'm overall responsibility for our technical services group um which you know comprises our developers and engineers and we're we're kind of responsible for making the magic happen um you know i've been with cask going on oh wow over seven years now as of two weeks ago um and then prior to that i was with a servicenow customer for six for five years so been around the platform since 2009 so back when they were named after the seasons and you'd get three releases a year and before scopes ever existed uh so i've been around for a little while um but uh i love the platform um i'm a firm believer in in that there's almost nothing that you you cannot do with the platform also from lessons learned some things you should not do with the platform um but uh you know you know it's it's i'm i'm really psyched to see it going in the direction that it is um because you know for for the longest time i kept hearing oh it's just an id ticketing tool and that would make me cringe so super like to be here today and uh glad to share this little use case that we we came across so yeah awesome yeah you have way more experience on this platform than i think i was still in college when you were working on this hey well thank you for making me feel old um no no no no you're well seasoned well seasoned well seasoned yes that's the perfect term you know my background was not as a developer my background was in infrastructure and support so you know i spent a lot of time in data centers and help desks and and field services groups but when i when i came onto the platform you know there was there were two partners it was fruition and uh the company that turned into cloud sherpas i forget what they're navigate um so you really had you really lived and died by the community back then um and it was super helpful like i just i can't count how many times i was rescued by the community because i wasn't a coder i didn't really you know i went i went did some online courses for javascript but wasn't my history wasn't my experience but just kind of had to jump into the deep end as a customer back then um and you know that was that was back when knowledge was held in a parking lot here in there in san diego that was about knowledgeable awesome yeah so so what are we what are we talking about today so uh you know a little bit about the use case um we we had a a recent customer that wanted to um they wanted to leverage something similar to the out of uh onboarding order guide but they wanted to do something interesting with a couple of the items that were part of that order guide so one of those items was you know the standard email request um you know what what what could happen in their environment is someone might ask for an email account but they don't know what email address they're going to ask for yet or the preferred email address might not be available and they don't have the integration back to active directory or exchange or o365 to do the double check on whether or not it's an available email address on submit so what what they asked for was you know we need to let hr and the hiring manager know if that email address like what's the final email address that they're going to get so what we wound up doing was um well we struggled with it a little bit because you know we originally we searched the community we searched you know all the standard channels um and couldn't really find a solution for monitoring variables after they've been submitted which i was actually a little bit shocked to not not see that you know prevalent in the community because i'd have figured it would be common for folks to be asking for um so you know a little bit of research led us to you know the the sc item option table which is where all the values of variables are stored on submit and we took a look at that table and said great this is this is where we need to be we can just dot walk from this to the to the to the rhythm and then use current.variables and an email notification to let the the customers and the stakeholders know that this is what the final email address is or your requested email address was not available and it's it's now changed um so uh long story short it turns out you can't dot walk your way to it because there's no actual relationship there's no reference field on the sc item option table back to the requested item there's a many-to-many table um i forget the name of it off the top of my head but there's a many to many table that's used that you have to query from the esee item option table to get to the requested item at first what we tried was to um excuse me i lost my train of thought at first what we tried was uh to use male script from a notification um uh and uh leverage an event that's triggered by the change in a business rule so that all was working we can trigger the notification but what we couldn't get to populate were the actual values the current values of the variables once they had changed um so doing a little bit of research um for whatever reason we couldn't get current.variables to work from inside or but we couldn't get anything other than current.variables to work uh so glide record dot variables rec.variables any any which way we tried to get to the variables by just using male script we we were unsuccessful so what we wound up figuring out was instead of using the default value which is passed in the event uh when you're when you're triggering your event you know your your standard value is going to be current and that's going to pass the current value of the record but if you tell the system no i want current to be something else we were able to actually successfully leverage that by telling the system current meant the stamp the the current requested item rather than the item option so what that then allowed us to do is to leverage current.variables for any variable that was on that requested item not just the one that we were monitoring so yes we're monitoring the email variable for change but we want to go ahead and now we can leverage all the other variables that are on that requested item like the requested for requested 4. manager hr department was actually a hard-coded email address but my dog um uh but you know so long story short it wasn't as simple as we thought but once we figured out how to how to trick servicenow into thinking that the rhythm was current and not the sd item option record we were able to successfully uh pass in any single variable so i'm going to share my screen now and let's just make sure in the right window here so this is my pdi and this is all out of box i didn't just lost dorian oh there he is um so uh john's still in the system so that's the word this tool okay yeah so you know i'm just gonna use the out of the box email account or email request so you know it's pretty simple i want nate cask llc dot brass casper x dot com that's our old email domain order now just gonna use the standards so this is the rhythm we just opened and we notice nate caskanex.com so if we wanted to see or monitor that variable for change we've got to do that on the sc item option table and i see i got a couple of entries here so i've been testing this just to make sure i didn't mess up the uh mess up the demo but uh this wasn't an actual card item but we noticed we've got nate caskanex.com now if i wanted to change that or let's say the email team comes back to my hiring manager and say sorry you can't have nade at cascanex.com because that's already been taken it actually already has by me um but uh let's just go we're gonna change this we're going to use my actual email address and i'm going to jump over to the sent items to just show you what a quick output of this would look like and does that change it on the the actual rhythm itself as well when you change that value there it does so uh let me let me show you it's a great question just so like if if they change it there it also changes it there as well yeah so so in the real world this would happen as part of a catalog task right so this would be an exposed variable on that specific catalog task either in flow or a workflow and we it would be writable for that catalog task only um and then the assignment group that's assigned to actually create the email address would populate it type it in um ideally you would want some sort of automation there but this this customer unfortunately didn't have that so but if you'll notice the preferred email address this is this is the related sc item option records so i could change it here i could change it as part of a catalog task i could directly change it on the table which i already did and it's going to trigger this notification that should be in the outbox actually because we don't have outbound email going on this so i added a quick notification and this is the value cool so the business rule and i probably should have been a little bit better prepared and had these just up i apologize but i wrote a quick business rule um naming conventions are going to vary for business rules typically we have something um that that we do for all of our customers just to let them know that that we were the ones that wrote it i completely ignored that here um and just wrote this quick business rule so when to run um i put after update you have to tell it which field you want to look for and then uh you have to tell it when the value changes otherwise every time the question is updated or or something else triggers your you may trigger this business rule um pretty straightforward conditions um actions we pretty much left alone and then in the advanced section this is where the magic happens uh so we are selecting uh so we are querying from the current sc item option table record to the sc item option many to many table which is what this glide record query is is handling right here so we find out what the current value of the the rhythm is and we pass that value here in the event queue so uh by default the second place in the event queue when you're writing to it is going to be what represents current so because we're passing gr here for current when we get to the mail script which i'll show well actually it's not even a male script it's just a simple notification once we get to the notification that's going to look that's going to be current so question nate real quick on that script yeah and this is going to go to like best practices a question there um because i see that you're using gr we know how yes some people get about gr yes yeah are you supposed to wrap that in a function or is it already considered wrapped in a function uh because um you should wrap that in a function okay um because by default business rules won't um when i forget yeah but i i would say that you should wrap that in the function jump okay perfect yeah i think i think though as long as the business rule isn't running in global in theory the script is running because it's a function up top like line one i don't think yeah it is yeah that's what i was getting after yeah and and don't get confused out there when when we say global there used to be a way to run business rules globally on any table um that's not the same as saying it's in the global application scope um when we when we and and it was a very strict use case that you're actually supposed to use global business rules those were since replaced by script includes a long time ago um so i i would definitely avoid you i don't even know if you can create a global business role anymore i think you can or at least i know of one because i had a bug a previous time and the bug was related to a global business rule that was running um the service now is global business rule not not like a custom one that was created no real reason to use those anymore um and to be honest even back in 09 you know back in the arts i didn't really have to use global business rules ever um but but again you know i didn't get into really complex coding back then i was just i was just trying to get into the problem and change off the ground so i do have a question about monitoring so i wonder is it is it possible to run the business rule on the the rhythm and then see i think there is an option for variable changes it's been a long time since i i don't actually know and then have your script manage when the variable changes because because the values are written to the the item option table i i don't know that a business rule on the request item would have picked that up i'm pretty confident that it wouldn't have because business rules monitor table actions not related table actions at least as far as i recall um john you might want to prove me wrong on that one it looks like you're you're you're questioning my no i'm trying i'm trying to think the last time i wrote anything like i'm trying to think of the the uh the query builder and if you can actually get into uh related fields that way and i don't i don't remember i don't think i ever go to tables through business rules yeah you know to be honest i've never really tried so maybe the next time we do this um we can give that a go yeah yeah i'm thinking like potentially just writing a business rule on the uh rhythm and then calling like current dot variables dot whatever the name is dot changes right like in the condition up there and then you then you have access to if it ever changes um again it's been a while so i don't this is this is really cool because i've never even like used this table so it's like interesting to know that variables live on this table it it so uh i think chuck did something a few years ago loosely related to this um so that's how we came across the the esee item option table um that wasn't too hard to figure out um but what what was a challenge was recognizing that you had to query the money to many table to get between the records um that was something uh that we had to figure out but let me show you the notification real quick and this is the one there's going to jump to what it will contain and if i wanted to add even though i'm not passing you know even though i'm querying nasty item option table for this because i'm using the rhythm now i can use oh well this is actually this is a table or a field on the rhythm itself so i don't even have to not walk my way into anything yeah that's i mean it was it was cool we you showed you know one a table where all of those items are or where all of the variables are you also showed like event you know event queue right and being able to manipulate event queue for for your own uses yeah and if if we had wanted to pass some some other information in we could use this part one and or excuse me part one and part two um but we didn't need to because all the information is is now uh readily available just by going to the requested item and and leveraging the current.variables um which actually used to be current about variable underscore pool um but now either will work yeah i'm curious i mean i know we're a little over but do you have a few minutes you want to just create a business rule um a new business rule and sure well you could if you wanna and i probably should have changed that to email addresses has been modified but awesome yeah super cool all pretty straightforward and just really tricking the system into thinking something else is the current record awesome yeah so i'm curious if you know maybe if we could do a quick little test here on on the business rules so if we write a new business rule on the requested item table and it's always interesting like whether to create the business rule or do it in a workflow [Laughter] i i don't know it depends on me yeah it's gonna depend on who you ask coders will be like business rule yeah front end guys will be like oh flo for sure yeah um you know and it's yeah i use the rule of thumb i use the rule of thumb for me as if there's no logic you're doing like you're not doing a bunch of if statements waiting for something and then doing it i use a business rule versus like if it's flow or workflow i have access to a bunch of like the if statements waiting for things to happen and then processing um i would say if you're less experienced with javascript and you can't do what you need to do by just setting field values with the business rule um your best bet is probably a flow right because it kind of abstracts the javascript layer out of it and as long as you can think in uh in and out and think like an algorithm then flow designer will work for you and that's actually how i got past some coding challenges recently you know where i just it was going to be a complicated bit of code and i didn't have a senior dev available to help me out so i just i pivoted to flow because i wasn't going to be able to figure out the javascript um so it can be helpful especially for low code no code situations now realize if it's again if it's not super complicated you don't have to use any code on a business rule you have the actions where you can set field values with no code i thought that was pretty nifty addition when they add that in you know i don't remember when that came out but that was i stumbled upon that one too that's definitely and that's what i meant by like using not condition builder but actions action site you don't have to know code to set values of things um i will say you know even though i'm not a coder i tend to default to that method a lot now though um you know because it's just it just feels faster to type it out than to deal with a bunch of clicks um but but i also do used to do a lot of network admin so um i am a big cli fan well as a coder i also agree i feel like i can make it do whatever i want because i can write the code that's not always the right answer no no no i know i know oftentimes it's probably the wrong answer probably but i can't see it because i'm too busy right now fair enough so yeah do you want to let's create yeah just we'll just click new and then put the table as the oh it's already there perfect when to run can you go to the choose fields is there variables in there uh on the when to run on the additional filter condition oh yes variables exist here i don't i don't remember no it doesn't okay so leave it on always and do select update and then just name this like test change variable and then under and then submit this because we're gonna go or click advanced sorry we need to you gotta save it before you get the option oh okay that button advanced on the right checkbox right under active there you go yeah cool and then go to advanced and and then type for the condition do up top so before you even get into the script do you like current dot variables dot and then whatever the name of that field we're modifying if you remember the name of that internal field let okay cool dot changes as a function yeah so now just do like a gs dot info or something there just to see if this runs right because i'm curious like if this would run you wouldn't need to use the other table right you could just you know monitor this granted this isn't efficient right because this business rule is going to run every time because there's no conditions for it um we can't do single quotes there nate oh yeah or or escape it yeah yeah yeah but what i thought the proper grammar has fouled me up i think where you would make this like like we could get more creative of like the filter condition to be only on these catalog request items right but i'm just curious if like if this monitors changes and and so if this fire is when you change that email address because it would be another a path you could go rather than querying the um or rather than writing a business rule on the option table and then you want to time it and see which one's more expensive if it works yeah we're always talking about being performant right we want performance i like it go check the best i only bring that up because i've been bit a couple of times on slow performance and uh it should be forefront in your thinking yeah yeah that's why i'm thinking i'm like all right the filter condition would be only on this catalog item right and well yeah if you can trim it down to only happen when it specifically needs to happen i think it's called that probably is yeah probably a little bit cheaper and so what nate's showing right now is the um the field type so if you ever wanted to access it in a script um you access it by its name this internal name rather than the the field that shows to the yep i'm just waiting for that refresh oh so that would not have triggered [Music] good check since this would be on the condition up top yeah all right let's give this a shot if this works we should rename this episode to teaching old dogs new tricks [Laughter] and fyi nate is my boss so it is it will happen i love it a little bit of fun on a third tuesday morning right tuesdays need fun because yes they get nothing else let's check the log and the info log and see if we also fun fact i never do info i always do error like like it runs like i can never find what i need you know see i just do dollars i do like three or four dollar signs in front of it and then i just do a search for dollar signs and i think you said it like star working or something like that i don't remember what you did yeah nope so or i think it was working no yeah okay so maybe that didn't that didn't fire um yeah so there's probably more i'd have to that was my initial idea when i when i when i saw this but there's there's got to be some way that the request item monitors those changes um it's interesting it's we like because i don't think i've ever seen a documentation about the the option one so i think it's like very hidden to most people and so that's why i was curious if um uh you know i think i found it somewhere in the documentation but i don't know i think i think you also made the modification on the option table directly could you actually do it on the rhythm instead to see if it fires because you didn't technically modify the request item yeah you only modified the google check oh wrong one give me one sec you know what i'm just gonna i'm old school there's so many can you tell us yeah being old school though really helps out i was on a project where they had renamed hr stuff and so you couldn't just do you know like case you couldn't get the cases in the left side they'd renamed it and so it was just much easier to type in snhr court case every time because she couldn't find it in the nav anymore yeah so yeah i love those i mean i always so when i used to teach the sysadmin class um i used to you know tell everyone show everyone that one as part of list demo and and just the interface demo and everybody was like oh wow i didn't know you could do that um and it was dot do dot list dot config and what's the other one those are the three that i use those are the few yeah those are the only three that i invest and and then capital versus not capital right yeah so yeah all right so let's see if our log showed up this time yes hey cool so that will sit we've worked too yeah awesome i liked your solution got to show different ways to do this this is this is actually a teaching moment there's lots of different ways to do a solution well that's just what i was going to say you know servicenow is so flexible it is it does you know you can do things a couple of different ways sometimes more than you even know a microsoft word doc right you can you can format things and get to the formatting menu and or use quick keys or do all these other things and that's the that's the power of a robust platform is you have options of of achieving tasks now some options are going to be better than others especially for system performance so you know like john said i'd be i'd be interested to see if if we had a more complex use case and had to monitor all the variables how can how can we do that on a requested item for a change for any change to any variable for like a regulatory type reason right so um yeah yeah and just for people like we did current.variables.you know new email you could have just done current.variables.changes and then that would essentially monitor any variable that changes and then just in your script you know access them so yeah yeah cool absolutely well awesome thank you gentlemen it's been a blast um hopefully you'll have me back sometime and uh yeah yeah i always i mean i always love when john's boss is on is on video [Laughter] it does be that we have a a message in chat oh that was that was me that was awesome we can talk but you know if there wasn't someone on stream it would show up on uh on our screen so oh okay well awesome cool all right it was fun yeah have a good day i'll see you guys
https://www.youtube.com/watch?v=7sM1qbZDDq8