Use #ServiceNow Catalog Item & Record Producer Variables like a BOSS! (ServiceNow Toolbox)
hey everyone and welcome to the first episode of the servicenow toolbox my name is robert fidork it is so good to have you here in this episode we are going to be talking about all the wonderful things you can do with variables now everybody who builds in servicenow should be familiar with variables already mostly from using catalog items but you gotta remember variables are used on record producers too now back in 1912 when we first started building on servicenow there wasn't a whole lot of things you could do with variables usually they were there just to collect information and possibly be used in a workflow script but if you want to do anything beyond that like put a variable on the column of a list view or as a condition of a report or anything else involving a condition builder there just wasn't very many options part of the reason for this is that catalog items and record producers both store the answers to their questions in different tables worse than that they're different tables depending on if it's a catalog item or a record producer the reason for this is anyway variables have come a long way since then and today we'll showcase how you can exploit them in reports business rules notifications and scripts today servicenow provides access to variable data for catalog items and record producers by having what looks like a reference field in condition builders for record producers this field is called questions for requested items created from catalog items the field is called variables so first up let's see how this helps us with reporting variables can be used in two fun ways in reporting first we could use them as columns in a report we'll demonstrate via records created with this record producer called report a mega issue reporter mega issue asks if the issue has stopped work and also how much the stoppage has cost us let's add the column how much damage to a list report to do this we go to columns we pick a special column called questions that asks us which record producer we want in this case report a mega issue and then we just pick the variable we want which is damage remember it's the same idea for catalog items except the column is called variables instead of question run the report and there we see our column with the variable data and for those of you who like your data more visual here's an example of a pie chart that has been grouped by a variable and you could see that it has gone through questions report a mega issue how much money did this cost us now the second thing we could do with variables in reporting is use a variable as a condition we're going to filter these incidents to just those where work actually stopped because it's a record producer we reach those variables through the field called question that will ask us which record producer stores the variable we're interested in then we just pick the variable so this condition says did this stop work and it's equal to yes two quick tangents here you still have to be very careful about the conditions when reporting on record producers or catalog items because not all the records you make will have the same variable that you're interested in when reporting on catalog items i always make it a point as a condition to specify which request items are produced by catalog items that contain the variable i'm looking for in record producers it's a little bit more difficult because it's harder to determine what record producer created the task luckily this information is stored in the sc underscore item underscore produced underscored record table you can see in this report that i have it as a related list condition i've specified that only incidents created by the mega issue record producer should be counted tangent number two we don't have the same field types in variables as we do for columns on tables it's 2022 and you still can't create variables that represent currency or numbers so you can forget on reporting based off numeric thresholds next up business rules now you'll rarely if ever have to use business rules on variables for requested items because requested items are usually triggering flow and flow designer is um but a couple times in my life i wish to have the capability of running a business rule of a variable is populated in a record producer we'll use my mega issue example from earlier where we want an event triggered if the record producer produces a record where the variable for stopped work is equal to yes now here i have a business rule with a script that triggers an event here i am in the condition builder first i want to go to show related fields then remember since it's a record producer we're using the question field and in this case it asks us for the record producer we're going to put in mega issue then the variable which is if this issue prevented work and we're going to set that to yes then we'll save the business rule then we'll test out the record producer making sure to declare that this prevented work we'll save that then we'll go to the event queue and see that the event has been triggered so now you're probably thinking service level agreements have condition builders can we base an sla off of a value from a variable you betcha and there's lots of reasons why you'd want to doesn't a requested item represent the execution of a known workflow and if we know the workflow shouldn't we know roughly how long it takes and the same holds true for things that we create via record producer shouldn't we be quantifying that promise via sla here's an sla i created for the mega issue record producer and it's triggered when the variable of work stoppage is set to yes and here's an example of the sla that got triggered based off of that sla condition once again for record producers in the condition builder it's question record producer variable and for requested items for catalog items it's variables the catalog item and the variable name word to the wise here if you're making an sla on a record producer take extra care because slas don't have related list conditions like reports do so it's a little bit harder to make the sla trigger only for those records created by the record producer you want in this case i got lucky because i'm looking for a specific value in a specific variable and thus all other possibilities are false notifications no problem we just use the same paradigms as before if it's a task created from a record producer you go through questions you pick the record producer then you pick the variable if it's for a catalog item you pick variables pick the catalog item then you pick the variable what i'm really trying to get at through this video is that you follow this record producers questions catalog items is variables method of exploiting variables on any type of paradigm that has a condition builder in it okay for the rest of this video let's try not to trigger the ocd no no no no try not to trigger the oh god oh god oh so the great news is we can use all the variables that we've entered via catalog items or record producers in our scripts you just have to forget everything you learned about dot walking through questions or variables because in scripts everything goes through [Music] the variables if you don't recognize this interface this is xplor the most awesome dev toolkit on servicenow if you want to learn more about it there should be a link coming right about here to teach you all about it otherwise check the description below so in explore i've created this script to log out variables from an incident i've created via record producer so in explore i prepared a script to log out the variables for incidents i've created via the mega issue record producer i've made two log statements one dot walks through the field questions the other dot walks through the field variables now up until now you've associated record producers with the question field let's execute the script and i see that the only script that gave me the output that i wanted is the one that used variables to dot walk to the variable that i wanted the same concept holds true to notifications in normal cases you'd use this dollar sign method to articulate fields that you want to include in a notification so if you want to include variables even if they're on a record producer you have to dot walk through the variables field in order to display the value that you want special bonus let's talk about flow designer and again please don't trigger the ocd by now you may have used flow designer to create flows for catalog items but can you manage a flow based on a task you created from a record producer and exploit variables at the same time anyone who's built a flow designer against a catalog item knows about the get catalog variables action but it appears to only work for catalog items would this work for record producers let's take a look here's a flow i've created for an incident and even though the action wants to collect variables from a catalog item i'm going to go ahead and enter the record producer then i'm going to pick the catalog item variables from that record producer here's the news that was created that ran that flow and you can see that the flow worked properly while collecting variables that only appeared to work for catalog items so despite the wording the collect catalog variables works even for record producers which is super handy for any flows you may want to run based off of tasks created from record producers thanks for watching servicenow toolbox please let me know if you prefer the long format or if this video would have been better broken up into 5 stink videos the servicenow playlist is looking for a few select elite sponsors all sponsors get a 30 second pre-roll in front of every video that appears in this playlist also if you aren't into making video content but still want to contribute to the servicenow community i'm looking for a handful of select content partners to help me write and prep content partners are eligible to participate in sponsorship revenue share thanks for watching and we'll see you next time do you want your message in front of the best servicenow admins developers architects and product owners in the business want a conversation about your servicenow strategy and architecture you can reach me via my website at www.theduke if you want to contribute to high frequency high quality servicenow content all you need to do is feed the algorithm with likes shares and comments thanks for watching
https://www.youtube.com/watch?v=nk9A6tBQvSA