
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
12-05-2021 08:33 PM - edited 08-05-2024 11:14 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
Decision Tables was the main subject in recent Platform Academy and Creator Toolbox episodes. Decision Tables was clearly explained and demoed. Below are the links to both episodes.
- 2021-11-11: Platform Academy Session #10: Getting Started with Decision Builder
- 2021-11-12: Creator Toolbox - Decision Builder with Julia Perlis
A question that did pop-up during the Creator Toolbox episode, how to track when one of the conditions gets deactivated. It doesn't nessesaraly have to be an issue, the next decision will just be evaluated. Though what if there are no matching conditions anymore because of this, or what if the defined result is deactivated, that could potentially cause an issue. My thought immediately, we might run Instance Scan on this 😀.
In two articles I'll dive into creating Scan Checks to check for the condition, and to check for the result. In this first article, let's get after checking the result!
Decision Tables
I've simulated the example from the Creator Toolbox episode as much as possible. Within the Decision Builder it looks something like:
What we are after, is finding out if Instance Scan can scan for the result "Group". If it's inactive or it doesn't exist, creating a Scan Finding.
Decision Question
After searching a bit, I found a table "Decision" [sys_decision_question]. This table holds an "answer" field which holds the value that we are after.
Decision Table result is inactive or does not exist
Knowing this table structure, we can start with building Scan Checks. Scanning for the result looks easy. Creating a Table Scan Check, selecting the Table, adding conditions, adding script because a Document ID field is used. With this we can quickly create a Scan Check to see if the result value exists. To also check if it's active or not is a bit more work. Not every table has an "active" field, and for this Scan Check I'm just ignoring that sys_choice actually has an "inactive" field or custom tables might have an "u_active" field.
Table Check
Table:
sys_decision_question
Conditions:
active=true^answer!=^decision_tableISNOTEMPTY
Script:
(function (engine) {
// Define variables
var table_name = engine.current.decision_table.answer_table.toString();
// Check if table has active field
var grActiveCheck = new GlideRecord(table_name);
grActiveCheck.initialize();
var fieldSize = grActiveCheck.getElements().size();
var fieldsArr = grActiveCheck.getElements();
var hasActiveField = false;
for(var i = 0; i < fieldSize && !hasActiveField; i++) {
var fieldNameStr = fieldsArr.get(i).getName().toString();
var fieldTypeStr = fieldsArr.get(i).getED().getInternalType().toString();
hasActiveField = fieldNameStr == 'active' && fieldTypeStr == 'boolean';
}
// Get record
var grResultRecord = new GlideRecord(table_name);
grResultRecord.addQuery('sys_id', engine.current.answer.toString());
if(hasActiveField) {
grResultRecord.addActiveQuery();
}
grResultRecord.setLimit(1);
grResultRecord._query();
// Create scan finding
if(grResultRecord._next()) {
engine.finding.increment();
}
})(engine);
---
And that's it! A nice Instance Scan Scan Check to check if the result on a Decision Table condition is inactive or doesn't exist.
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Platform Architect @ Quint Technology
2x ServiceNow Developer MVP
2x ServiceNow Community MVP
---
- 1,998 Views