Conditional Breakpoint in ServiceNow Script Debugger
00:00:00.270 --> 00:00:02.720
In the previous video I've talked about the script debugger 00:00:02.720 --> 00:00:04.190
and setting up a break point. 00:00:04.810 --> 00:00:07.390
You could find the link for that video in the description below. 00:00:08.280 --> 00:00:10.820
In this video, I'm going to talk about the conditional 00:00:10.820 --> 00:00:14.454
breakpoint. While having the
ability to set breakpoints is 00:00:14.454 --> 00:00:17.897
useful, there may be scenarios like executing a for loop or 00:00:17.897 --> 00:00:21.340
iterating over a list of items where the execution would have 00:00:21.340 --> 00:00:25.096
to be paused many times if break point is inside the loop. 00:00:26.150 --> 00:00:28.326
So that is where you can use the 00:00:28.326 --> 00:00:32.086
conditional breakpoint. If you
use that, instead of pausing the 00:00:32.086 --> 00:00:33.621
execution on the same breakpoint 00:00:33.621 --> 00:00:37.213
multiple times, you could set a conditional breakpoint which 00:00:37.213 --> 00:00:40.603
would pause the execution only if the condition specified by you 00:00:40.603 --> 00:00:41.620
evaluates to true. 00:00:42.410 --> 00:00:45.230
Now let's take a look at an example using a Script Include. 00:00:46.030 --> 00:00:49.150
This is a Script Include I have created for this demo. You can 00:00:49.150 --> 00:00:50.590
see that there is a breakpoint 00:00:50.590 --> 00:00:53.833
already set here. And this is
the method that I've added in 00:00:53.833 --> 00:00:54.454
the Script Include 00:00:55.490 --> 00:00:59.162
which would return me an array of values. In this case, these 00:00:59.162 --> 00:01:02.834
are the prices you can see that the Script Include name is 00:01:02.834 --> 00:01:06.330
InventoryPrices. Now let's go
to the Business Rule 00:01:06.330 --> 00:01:08.625
onInventoryUpdate that I've created in the previous demo. 00:01:11.900 --> 00:01:15.787
You can see that I made a few changes to the script. I'm 00:01:15.787 --> 00:01:19.076
calling the new Script Include over here and the method 00:01:19.076 --> 00:01:22.365
getLatest which would return me an array of values from 101 to 105. 00:01:23.150 --> 00:01:24.870
And I'm iterating over those 00:01:24.870 --> 00:01:28.107
values here. Now let's put a
breakpoint over here 00:01:29.350 --> 00:01:32.182
and update the inventory table which would trigger 00:01:32.182 --> 00:01:33.244
this Business Rule. 00:01:35.020 --> 00:01:36.917
And let's open our debugger before that. 00:01:38.450 --> 00:01:39.920
You can see that there are two 00:01:39.920 --> 00:01:43.508
breakpoints. One in the Script
Include InventoryPrices on line 00:01:43.508 --> 00:01:47.118
number 7 and the other one on Business Rule at line number 9. 00:01:48.370 --> 00:01:50.428
Let's go back to the inventory table 00:01:54.130 --> 00:01:57.058
and update the category from 'Computers' to 'Computer'. 00:01:59.900 --> 00:02:02.177
You can see that we got the debugging notification. 00:02:03.640 --> 00:02:05.047
And the first break point is hit. 00:02:07.150 --> 00:02:10.615
Once we resum the execution, we go to line number 9 in 00:02:10.615 --> 00:02:11.560
the Business Rule. 00:02:13.400 --> 00:02:15.386
Now observe what happens over here. 00:02:17.150 --> 00:02:19.977
You can see that the value of 'i' keeps on changing. 00:02:21.470 --> 00:02:24.593
Because we're iterating over the items from the 00:02:24.593 --> 00:02:25.287
getLatest method. 00:02:30.520 --> 00:02:32.417
So you can see that it executed 00:02:32.417 --> 00:02:35.807
five times and the execution has been paused five times 00:02:36.410 --> 00:02:41.090
at line number 9. The problem
that we face right now is if I 00:02:41.090 --> 00:02:44.810
want to pause the execution only when latest price value is 103. 00:02:44.810 --> 00:02:48.220
In that case I would have to resume the execution twice. 00:02:49.030 --> 00:02:51.874
You can overcome that problem using a Conditional Breakpoint. 00:02:52.560 --> 00:02:56.040
To add a Conditional Breakpoint, you can right click on any breakpoint 00:02:56.040 --> 00:02:57.490
and press 'Add Condition'. 00:02:58.500 --> 00:03:01.836
In the text box that is presented to you, you can write 00:03:01.836 --> 00:03:04.894
any boolean condition. In my
case I want the latest price 00:03:04.894 --> 00:03:06.006
value to be 103. 00:03:12.190 --> 00:03:14.310
Once you're done with the condition, you can press enter. 00:03:15.650 --> 00:03:17.846
You can see that the breakpoint color has changed 00:03:17.846 --> 00:03:20.530
and if you hover over it, you can see the value 00:03:21.580 --> 00:03:23.038
of the condition that you entered. 00:03:24.740 --> 00:03:27.380
Now let's go back to the inventory table and update a row. 00:03:33.210 --> 00:03:34.720
We got the debugging notification. 00:03:35.800 --> 00:03:37.018
And the first break point that 00:03:37.018 --> 00:03:39.294
is hit is the Script Include 00:03:39.294 --> 00:03:43.170
InventoryPrices. And if I resume
the execution, it goes to second 00:03:43.170 --> 00:03:44.250
breakpoint which is 00:03:44.940 --> 00:03:46.698
line number 9 in the Business Rule. 00:03:47.440 --> 00:03:50.560
You can see that the 'i' value is 2.0 instead of 0.0. 00:03:51.160 --> 00:03:54.070
It means that the for loop is already executed twice. 00:03:55.570 --> 00:03:58.793
And if I press resume again, it will stop the execution 00:03:58.793 --> 00:04:02.016
because this is a conditional breakpoint. We won't reach the 00:04:02.016 --> 00:04:03.188
value of 'i' 3.0. 00:04:06.360 --> 00:04:09.330
So that is how a conditional breakpoint works. Apart from 00:04:09.330 --> 00:04:13.191
adding a condition to a breakpoint, you can also add a new 00:04:13.191 --> 00:04:15.567
conditional breakpoint by right clicking on the gutter 00:04:15.567 --> 00:04:17.052
and pressing 'Add conditional breakpoint'. 00:04:19.570 --> 00:04:21.560
You can press anywhere on the screen to save it. 00:04:23.380 --> 00:04:25.078
And you can also remove a condition 00:04:26.490 --> 00:04:27.519
or edit a condition. 00:04:30.750 --> 00:04:33.810
And if we remove it, it will become a normal break point. 00:04:36.870 --> 00:04:39.582
And you can also click on the break point or a conditional 00:04:39.582 --> 00:04:40.486
breakpoint to remove them. 00:04:44.270 --> 00:04:46.976
You can also perform the same operations in the script editor 00:04:46.976 --> 00:04:48.206
where you write the script. 00:05:02.900 --> 00:05:06.267
And if we go back to the debugger. You can see that the same 00:05:06.267 --> 00:05:08.339
conditional breakpoint is reflected over here as well. 00:05:10.290 --> 00:05:13.250
And that's about the conditional breakpoint. In the 00:05:13.250 --> 00:05:16.950
next video, will look at the debugger actions. Meanwhile, if 00:05:16.950 --> 00:05:19.910
you have any queries, please reach out to 00:05:19.910 --> 00:05:20.280
community.servicenow.com.
https://www.youtube.com/watch?v=9nozDeAVQow