Measuring Metrics in Scopes doesn't work
the other day i was in a situation where i needed to make metrics work on a scope table that wasn't tasked and so i went to the community and i found a post where somebody said hey i did just that but they didn't say how they did it so i went again this video will walk through those steps before we get into that let's do a quick overview of how metrics work metrics are triggered by a business rule that rule creates an event with the modified fields and the update number the event is processed by a script action the script action reverts the record in memory to the version it was at the update time for the fields that matter then calculations are made based on the values at the time and now and it stores those as the measure why does this fail and how do i know this all right well there's two parts to this that we need to recreate where we'll go and i'll show you exactly where it thinks first there's the business rule we'll need to make a new business rule and if we want to make this work within the scope we would have to make this in our scope so i went ahead and did that i copied the script exactly as it was and one of the things it calls is this glidescript record youtube which if you run it it will fail so i couldn't tell exactly where it was failing in the business rule so i threw the code in a fixed script that i ran it manually and it told me that the glidescript record util wasn't available in the scope and i couldn't add it because it's not a script include so i was able to recreate the function to determine the fields that changed the next point of failure in the business rule is a use and active query on glide record which just isn't available in scopes so i change the query from add active query to add query where active is true then it makes a call to this glide db object manager class which gets the table and its extensions there was some code on the community about how to recreate this function and so i was able to do that as well fantastic we're almost there everything was looking great so far and then i got this message that metric update isn't accessible or isn't there like it wasn't found that's the name of the event that gets triggered and so i was like well i want to keep everything in my scope so i'll just make a metric update event in my scope now we need to recreate the script action to have it call this new metric and parse it properly in the script action everything looks like it works just fine there's a call to the global db object thing and i was able to solve that just like it was in the business rule but then there's a call at the end of it to this glide record rule back which seems to do the logic of reverting the record back to the version it was at that update number which is protected and not available to scopes and this is where the trail ends if somebody rewrote this so it could work you could potentially make this all work within a scope but today that's just not possible so the workaround is you just build the business rule in global let's tell servicenow to make this better by asking for access to these protected classes if you like this video and the content please like and subscribe and leave a comment about your thoughts below on maybe other ways to handle this thanks
https://www.youtube.com/watch?v=PHn90Hp03Ho