NOWCommunity Live Stream - Behind the Answers - Before query business rules

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] good morning good afternoon good evening wherever you are and whenever you are welcome to the community live stream my name is chuck tomasi senior developer evangelist at servicenow just checking the levels things look good welcome thank you for joining me this is the show that takes you behind the scenes on the community questions and answers and things that customers ask me and stuff i learn and just want to show you so you can be a more effective servicenow administrator and developer take those skills to your organization and learn how to reverse engineer do all that cool stuff and be better at your job and hopefully get promoted and more money and a beautiful house with a wife and kids okay i can't promise you all that but what i can promise you is today we'll be talking about before query business rules this is under the topic of behind the answers because a customer came to me a week or so ago and said hey chuck i've got a question where why what's going on here and we discovered it had to do with before before query business rules and i went hey i haven't covered that yet let's go talk about that that'll be fun because if i've missed this in that explanation then well now we have a place to reference it good morning to everybody who's checking in on youtube make sure you hit the right button there thank you very much for joining you know what to do subscribe to the channel that you see right there on the bottom of the video turn on those notifications get the notifications and you will get a secret prize on your mobile device that says hey we are streaming on twitch and youtube just like you see there i like them i get them it's fun i subscribe to a whole bunch of channels and it's like a little christmas present every time wow people are checking it all over the place i'm not even it would take the rest of the hour to read these names thank you thank you very much for joining uh some for some regular names and some new names thanks for joining i saw that it looks like the audience is up a little bit today i think it's a holiday in india so appreciate you joining and staying up for that that's why i say good morning good afternoon good evening because i know people are watching live from all over the world they're doing so by going to that url if you find something helpful in here you like something you know what to do click the like button or if you're in the community click the helpful very much appreciate it and it shows others that there's something useful in here comments are always appreciated as well oh i skipped right over the twitch you are let's do that real quick if you want to watch this on twitch for whatever reason there may be technical issues with youtube sometimes there are knocking on fake wood here to get yet a little bit of luck that hopefully the streams will hold up today and we will be in business so go over to twitch if you want to watch there although i only monitor the comments on youtube because of well it's a one-man show in the mornings here and i'm doing the screen switching i'm doing the title switching up due to all this other stuff well you're searching around the internet don't forget i invite you to go over to developer.servicenow.com get yourself a free personal developer instance they are now available with our latest release of paris had to think for a minute the time is going by so fast it's now paris time early access began on july 23rd we've got a techno webinar out that we will have a badge on the site so you can watch that if you missed it great stuff learn what's in the paris release from the platform perspective other information will be coming out about itom and itsm and customer service management and hr all those other things that will be coming out we just want to make sure that developers who had early access had early access to that information the apis are updated the documentation is updated the learning material on developer.servicenow.com is updated so go over there take a look get your feet wet i upgraded a couple of my instances just last night so looking forward to hooking up some of the things like open id i want to allow people to use google or facebook to log into an instance i want to try the new portal self-registration so i don't have to write and maintain my own there's a lot of neat stuff in there graphql start playing with that drew had a video on that where he's experimenting and just demonstrating as he goes wonderful stuff developer.servicenow.com also if you happen to be looking around check out the meetups one of the things you can find on there let's go like this i got to get the meetup screen to show the meetups meetups.com pro let's get that caption back up there slash service now dev program there are many many meet-ups that went to a minneapolis one last week we have madison i believe tonight madison wisconsin and phoenix arizona where i'm based will be on thursday so even though you may not be in these time zones we're doing these virtually which gives you more capability to join one or more meetups i love it because i get to go to so many without having to travel and if the schedule lines up and i'm in your time zone i will do my best to attend look forward to seeing that these are developer meetups by developers for developers about developer topics it is not something servicenow pushes in your face it's not marketing it's not uh it's focused on developers it's exactly what it sounds like we provide content to help with the topics but we don't do the presentations generally unless we're invited i've been asked in phoenix to present about the the paris topics on the platform so i will help mike with that thank you very much for joining i'll just quickly scanning down the comments no everything looks great thank you very much let's get uh oh quick reminder if you haven't done so already please tell us about apps you've built on the now platform we'd very much like to hear about that so that you can help out people with the covid virus so we can donate on your behalf fifty dollars per app up to five apps up to two hundred dollars we'll donate go to the bitly link there tell us what have you built whether it's a utility for developers whether it's something you built for yourself to make your process easier or something for your organization to streamline and digitize that's what we would love to hear about because we're looking for those stories of what people have built whether it's no code it's just a simple table to get people off of spreadsheets and centralized or you've built a whole workflow that goes across your organization and is now the core of how you make money anywhere in that spectrum we'd love to hear about it invite you to check out the breakpoint podcast brand new the first official episode the podcast is out there the first official episode which i'm calling episode one is coming out wednesday at midnight pacific time so it's uh what about 36 hours away from this roughly maybe 40 hours if you subscribe now you will get that automatically delivered to you this is conversations i have with our internal people and external people customers aka external being customers about apps and features and platform stuff conversational so no power points no demos no update sets you just get to listen to a 20 to 30 minute conversation with me and someone in our organization or occasionally a customer about things they've built or how it's built or features we want you to know about just fun stuff and oftentimes it will align with the techno topic so for example if we look at tech now great segue to their accidentally charles on august 18th we have a tech now coming up about building now experience components with wolfgang very smart guy also runs his own youtube channel called barely functional developer i believe it is go check that out he's got five episodes last one was nice and short i like them that way the uh bitly link there is how you register for that webinar and we'll be talking to him and then in a few days we'll have a podcast more of a conversational thing with wolfgang about the now experienced components so go check that out a lot of fun looking forward to bringing you more break point looking forward to bringing you more tech now looking forward to bringing you more community live stream and yes there's just more more more we will be doing a little bit of javascript today and if you want to be more familiar with javascript i invite you go check out the javascript learning series that you see there bitly sn learn js go through the whole series i've had a lot of people come back and say wow this really helped and i'm glad i'm really really glad it could be helpful we do if we do write a little code today and i think i'm going to have a little business rule stuff in here because it is a before query business rule i'll put that in the github repo that you see there and you can click through it on the description in youtube or on the community i'll have that linked back as well so look forward to bringing you that and with that i think it's time to start our main topic got everything done yes yes let's go check the notes and right on top so i have a request this this came in from a call that a customer had some of you may be familiar with the application that i wrote years and years ago that's still available for managing loaner temporary loaner assets it's called the loaner request system you can find it on the developer portal go under share look for a loaner request you'll find it you can download it install it on your pdi try it out well chaz and ben from one of our customers in pennsylvania called up and said we have an issue because managers can't see the request that they're looking that they're trying to approve they put in an approval in the workflow perfectly same thing to do you may want to get a manager's approval before you let out a laptop or a vehicle or something else so these temporary laptops could have an approval you could put whatever workflows you want on these things just like any other task record well they said that's all fine and dandy let me show you what happened they went to a screen like this and i'm i'm logged in as luke wilson and said show me the approvals and i have a quick handy-dandy reference here it says here are the approvals come on there we are and it says luke i'm logged in as luke up here the blue screen will be luke wilson one of the managers out there luke you need to approve this it goes into the the record that says okay so i'm supposed to be approving but i can't see what i'm approving and down here in the corner it says summary of item being approved record not found i went well certainly the record is found let's back up and try that again with mr tomasi who has admin access and i look at the approvals and i go into the same one luke wilson's 1002 record and it says sure there's all the data down here it gives you this nice summary screen of section zero we've talked about this before i should do an episode on how you can figure that right there that form section you can make this tailored just for the approvals but anyway the uh the details were there i said well that feels like an acl thing and it really wasn't it we tried putting in an acl that didn't do it it came down to a before query business rule now if you join me on the last episode on july 30th you'll know that we did reference qualifiers and reference qualifiers are a way to filter data on a record so if i go into say this record oh let's i real quick review reference quality qualifiers allow you to put a simple or dynamic or an advanced aka scripted way to filter the records that are presented in a reference field when i click the caller field in incident do i want to see all the callers do i want to see just the active callers do i want to see the active callers with a certain role you get the idea i can filter that but it's field by field so if i have the same filter across many tables maybe all the tables that doesn't help me too much i don't want to track every one of those so i've got the flexibility of configuring it field by field with a reference qualifier but i can also do it on a more global scale with a before query business rule let's take a refresher on business rules in the docs page if you look up how business rules work that's all you have to search for that's the name of this article this is the paris version how business rules work there is a diagram that's been here since i think 2007. it's an old powerpoint screen grab i've made my own version of it but this is the one that lives on right up here at the top thing says user or system query someone is asking for a one or more records i would like to see the information on this okay that is where a query rule comes in this whole lane is sort of where you can see where business rules act the one that's missing here is an async business rule which is sort of over here on the side next to after rules so we'll take this diagram with a grain of salt that it needs a little tweak when you query it goes and does that database query then display rules what should i do before i show you these records person fill something out that's what roughly this arrow is doing something with the form looking at it then eventually they click the submit save update whatever you want they say database i'm done take it a before rule runs before the database update that's the beauty of this i can make little tweaks like hey the short description should be this field plus that field i do not put in an update operation into a before query business into a before business rule because i'm getting one for free right here and if i do put an update it's going to start the whole cycle over again and go well hey you're doing an update so it's like somebody submitted so i'm going to run around here a couple of times and say now i've been here done that don't want to do it again after rules run after the database update general rule of thumb for those of you who forgot before rules are generally not always generally done on the current object on the record you're looking at so priority equals impact plus urgency something of that nature it happens for free i'm getting an update so i'm going to tweak these settings before i save the record not always with the fields that are displayed on the form it might be something that's happening behind the scenes okay then after rules generally are done on records after the update related records after the update happens or triggering some sort of update that's going to impact other records the reason you do that in this order is because if for some reason one of the before rule says hey stop don't do this abort uh you don't end up with related records in a state that don't relate to the current record if i were to say hey let's go change let's go close all the child tasks because someone said close the parent task okay let's say change and change tests our relationship here and i close the child tasks change tasks before the parent change task they are now in a state and then this says abort so this is not really closed but these are that would be bad okay that's why before current after related stuff you can put together whatever mnemonic you want or put it on a t-shirt if you like to go with that okay back up to query rules at the top of this stack that allows me to do some data manipulation some filter and there are some that are available out of the box that say uh let's let's do this let's go like business rules i can type in ssru over there nice little shortcut that i've got there's your handy dandy tip for the day you don't have to start typing business or you'll get business services and all that other stuff let's pick the ones where the the type when i can never remember the name of this field because i don't use it all that often when to run when is display let's see what we get out of the box and maybe table is incident keep this simple aha load incident models into scratch pad no i'm sorry i didn't want any display i wanted query as true true i did that before i mixed up my queries and my so query is actually a check box in the business rule let me open that up and show you what i was talking about if you check the advanced button you have delete and query this one's display but query is a checkbox it's not the when field always fun to see chuck make mistakes like that so let's say query is true and table is incident and i have this one called incident query aha all right it's not running on insert operations or anything else just query it's before don't ever ask me if there's like an after query business rule and there's an advanced that runs this function now this is an older one so it's got a call to itself typically you'd see this running in an i think it's an ieff self-running function that says it starts with a parenthesis it says function execute or on execute or whatever it says so this is a little older syntax but it does the same thing run this function and this function says hey if you don't have the itil role and you don't have the sn incident read and this is an interactive session meaning it's not an api of some type then i'm going to see if this plugin is active otherwise look down here it does a current.add query that's what a before query business business rule is set up to do it says i'm going to apply this extra filter as if somebody went into the database and said you must adhere to these rules also it says the caller id is you or it's open by you or the watch list contains you those are the only ones you'll be able to read otherwise you could end up seeing things you shouldn't see and clicking them and acls will say no i'm sorry you can't see that which is what happens when luke goes into the approvals list and sometimes you see this message number of rows removed by the from this list by security constraints this is really irritating especially when you have a long list and the person has like three of the ten thousand records that are in there it says removed my security constraints 20 next page rows removed from conservatives 20 next page nothing nothing nothing and then maybe they get one record like that's that's a terrible user experience i wish we could have a check box that just says you know what if i don't have security remove it so let's go and make that was a long setup for that topic but hopefully you understand see business rules and where before query business rules come into play and one of the cases where you want to use them and one of the reasons why i put one into that loner app is to remove messages just like this however the rule was lacking in one thing let's go and take care of luke's example here on the approval list to say if you can't read this then let's get take it out of the list and you'll see this goes from 20 of 679 watch this uh 16 removed next page next page 18 removed 20 removed who's gonna do this all day and go just show me the ones that i've got access to for crying out loud that that makes no sense let's go and i think i have here we go we are going to create one on the approval list so i'm going to go to global real quick change my scope over to global and make a before query business rule for the approval list so back to system definition business rules just let's make sure i don't have one that's already there name of the table is sis approval underscore approver and i want to also see if the hand query is true run that ah i do it's currently active false maybe i already made this last week while i was setting up uh no i did not make this one but there is one available it says if you don't have the role approval admin and this is an interactive session again no api is involved then i'm going to append this on to you the approver must be you somewhere in this list okay and there is a function or a script include or something out there called get my approvals this will build it for me then it says query restricted to user list that's going to go into the log let's just turn this on and see what happens i update that i know luke doesn't have approval admin role and if he refreshes this list because i'm not modifying acls or roles it's just going to work notice now he's got 20 of 63 there are no more crazy messages that say you can't see this it's a pre-filtered list that he cannot manipulate it's going to show that all the time john says there is at least one submission in the idea portal to give the give us the option of acls to show the lack the tacky message or just show the results maybe if we get more people supporting it they'll implement it i could see this going another way that it wouldn't be just acls it would be on the list say you did configure list layout or list controls i can't do that because i'm luke right here and you could check a box that says if i can't read it don't do it okay that might be another way to do it uh you know adhere to read on display or something equally cryptic i'm sure our developers have a better way of doing that i could see that just being a checkbox on the list saying i don't want to mess with it or even a property that says globally do this there's a number of ways we can implement this at different places in different layers maybe we'll have that discussion sometime but when you use a property when you use a user preference when you do a lot of this stuff so anyway luke's problem has been fixed i am now filtering records that he can't access to avoid that nasty error message and that's exactly what i wanted to do in the loaner request app however we still have the issue of go back to the loner app and say go in here and it says record not found that business rule is missing a condition and i need to implement that well the easiest way is let's start out by going to studio and finding it because i'll show you exactly what it's doing and in my loner app i should probably put out a new version for this including flows instead of scheduled jobs and all that good stuff maybe this is the catalyst that will eventually that will get me to do that under server development under business rules and it took me we had a 30 minute call and it took me maybe 20 to 25 minutes to just figure out what was going on and then once i found it out it was very easy to fix and there is show my loaner requests which is a display query business rule if i got the right one it's advanced when to run before a display query i mean before query apologies for that before query i could have found this with the same filter on the loaner request table and look at what the condition does it doesn't care who's doing this it just says well actually it does care there's a condition and it says if you don't have the loner user role because loner user in this application is very much like the itil role in itsm these are the fulfillers these are the resolvers these are the people that are carrying out the actions to get you your loaner item so you don't have to give a user role to everyone who's using this application that could run into license issues you give it to the people who are managing the loaner assets there you go i've got eight people with this and 3 200 that don't have this so those people that don't have this role are automatically getting filtered and says if you're not the requester you're not going to see this record period oh well that's terrible let's see if we can fix that what is the condition that luke should be seeing well it should be more like let's go find the loaner requests there aren't too many of them so let's look at all of them there's only three it should be is luke the requester just like i have now or was it opened by luke maybe it was open on behalf of somebody else or maybe it was changed after he opened it and said you know what this isn't going for me i'm sending someone else on the trip give them the laptop change the requested four but the open buy still works as luke it could be that luke is the manager aha well since we know who this is and my approval is for the manager i can dot walk to the manager very easy to do let's first build that out in the list filter to see what that might look like so it's going to be and if you watch my reference my reference qualifier video on the last one there's a reason these two lined up this way it makes it very easy so start with the easy one if requested for is dynamic and it defaults to me so it uses whoever is at the browser to put their sys id in there i'm not getting this from a gs.get user id keep the scripting to a minimum kids this is where it gets fun or i could say opened by same kind of thing is dynamic me that says luke are you the requester are you the open buy or we're going to go down here and you may not have seen that at first these little arrow fields but those got turned on because i said show related fields let's turn that off just to show you what it looks like normally my reference fields are just looking like any other reference any other field in the table but if i go down to the bottom of this choice and say show related fields now the reference fields allow me to drill in or as we like to call it dot walk and i'm going to go find the requested for and not take the field value but go into the field value and now this list says here's your learner request fields but here's the requested four fields inside that and i'm going to go down to manager manager i could also drill into that one and go further but i don't need to manager is dynamic me same kind of thing i now have a multi-tiered condition that says luke you better be one of these people if you're going to see this record and if i run that obviously chuck isn't well i must have opened some of these so which is why they're showing but if i take that right click on the very end and say copy query okay it shows static values up here like is chuck tomasi but if i go over to vs code and paste that in as i showed on the reference qualifier video notice it doesn't say requested for equals some society it has this dynamic keyword in that's how it knows to use the dynamic filter and go to this particular dynamic filter oops let's not do that and substitute my society in for that value so it's doing this real time substitution these are done on the fly i have everything i need for my query now so let's take that and put it into my script if you don't have the loaner user role i'm going to run this script for you and instead of add query let's just comment out the original one and you want to say current dot add encoded query because that's exactly what this is boom looks big nasty and ugly but it does a wonderful job and i update that again i didn't change any acl so i don't need to log out and log in as luke i can go over to my approvals again that list is fine still looks fine i didn't touch that one the approval business rule the before query business rule is still in place still doing it's a wonderful job but if i go into say loaner two i can now see the details because i have read access it didn't filter it out for me that was a very tricky thing so be aware that before query business rules may actually restrict your visibility to things that other people like managers need to see so as you're building these conditions for your before query business will make sure you include various parties not just like i did and say hey if you're not the requester you don't get to see this okay and additionally what i i think i forgot to show you this before but if i click this before we say record not found because you can't see it it's like totally not part of the query now i can i've still got the acl set up right so luke can't change anything on this record whereas abel could come in here and probably change the date and add a comment to that sort of thing very much modeled after a typical itil expression but i'm not using an itil role to do that so that is what i've got approvals work before query business rules are a great way to filter the records globally because no matter where luke goes anytime he needs to reference one of these rec one of the records on this table because remember the before query business rule is on this table any reference field that shows this table is going to be filtered the same way it's going to run that condition and say hey do i need to apply this to you if i do here's what i'm going to apply you can make these as simple or as complex as you like you can base them on rolls you can base them on other conditions that you look up from other records somewhere in there you're going to add a current.add query it applies to lists it applies to single records or add encoded query or some way to add an additional filter the logic is completely up to you it is a scripted operation so again if you're not familiar with javascript and you want to get a little more familiar javascript series sn bitly slash sn-learn dash js is the place to go uh john says there's at least one submission oh you already read that missing a semicolon at the end of the ad encoded query i did i did it's optional this warning is saying you're missing a semicolon i was not watching that closely javascript that little available checker thank you for catching that by the way so do you have to code slash condition in delegates as well you could you may have to for the approvals i i don't know that logic may be taken care of in the delegation i haven't done delegation in quite some time so worth looking into a good question maybe i'll make that a future episode and as you saw you can apply these conditionally i have just one condition on this one that's where the condition makes sense again a good practice for business rules if you only have one condition why are you running the script only to say if not gs dot has rolled blah blah blah okay if it's only one condition put it in the conditions field if it gets more complex with if else if or you're doing a switch statement in there sure put it in there but this makes it easier to debug because if i ever have to go back and look at my business rules i turn on business rule debugging i will see this is skipped for admin but it is not skipped for luke i can go through that trace and say did this run or not and it will say skipped because the condition wasn't satisfied oh great but if it's run for everyone and i'm not using that condition field effectively it makes it a little harder to debug now i've got to go into the script and start saying did i run this did i not is it running here is it not running there turn on the debugger put a breakpoint in there did someone say breakpoint sorry i'm not conditioned to hear that that that word now means podcast to me it's been uh you know a month or so since i've been working on that so it's but it's going to happen you probably have situations like that as well steve says i usually use this feature when adding rows or changes for debugging i intentionally leave out the semicolon to easier spot the temporary change oh that's an interesting tactic sure if you're putting something in i will often put something in like comment temp like that so i can search for those i often do to-do's that way too if i'm thinking ahead and i've got to implement different layers or i know something's going to be in a future version i'll put in slash to do colon put that in and then i can go back to the code search thing and say where's to do found so everybody's got their little tricks when they're dealing with their code okay so keep in mind that these can get in the way if they're not doing what you expect and it looks like an acl rule it may not be an acl rule it may be a before query business rule check and see if your table has any before query business rules remember how we did that i said get the right pointing device here went to the business rules table under system definition ssru system definition business rules query is true and table is whatever your table is so you can find them debug them hopefully get yourself out of a hot spot faster than i did keep that in your back pocket and that is pretty much all i've got to tell you about before before query business rules thank you everybody for joining me today it has been a wonderful time wonderful audience great interaction with everybody i recommend i invite you to go to the community at community.servicenow.com ask your questions there participate in them some people have gone to asking me questions in email or linkedin messages i typically don't do that because it's an audience of one and if other people have the same questions it's not scalable this is the place you want to go to ask your questions because it's an audience of hundreds of thousands of people and other people can come along later and go oh that's exactly what i was looking for or if you're looking for that video on before query business rules you now know where to find it so go over there thank you for joining me hope you had a good time don't forget to click the like and subscribe and notifications and all that good stuff and until next time hope you had a chance to learn share and be helpful with something and i will talk to you again real soon take care bye [Music] [Music] you
Info
Channel: ServiceNow - Now Community
Views: 2,186
Rating: 5 out of 5
Keywords:
Id: Xtj9nvnryr8
Channel Id: undefined
Length: 37min 58sec (2278 seconds)
Published: Mon Aug 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.