- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Here's the question we will try to answer: Which flows can cause updates to records on the incident table?
The ScriptableFlowAssociation GlideScriptable (which drives the "Flow Designer Flows" UI Action) associates flows to a table through trigger records, we can learn from this scriptable, however we need to look at actions not triggers.
When an action is added to a flow, an action instance (sys_hub_action_instance) record is created. This record is an instance of an Action Type (sys_hub_action_type_definition). Actions have variables. For example: an Update Record action has table, record and field variables. There is a complex schema linking Action Types and Variable Definitions to flows, but all we really need to know is that there is a set of tables that define actions and variables, and another set that stores the instances of those actions and their variables.
Action Instance schema map. Not seen here are references from variables that use document/document_key references.
Getting back to answering our question, we want a list of flows. The Action Instance table contains a reference to flow, all we need to do is filter this list of Action Instances down to those that have a table variable set to incident.
To do this, we need to join the sys_hub_action_instance and sys_variable_value tables. Unfortunately, due to complexities in the schema, the variables don't directly reference action instances instead they use a document/document_key structure.
Instead of a simple dot walk, we can use the addJoinQuery() GlideRecord function to create the query. Since the action instance holds the reference to flow and we will need the value of it, the sys_hub_action_instance table will be the primary GlideRecord and the sys_variable_value table will be used in the join.
Here is a code snippet.
var actions = new GlideRecord('sys_hub_action_instance');
var action_variables = actions.addJoinQuery('sys_variable_value', 'sys_id', 'document_key');
action_variables.addCondition('value', 'incident');
actions.query();
var flows = [];
while(actions.next()){
var flow = actions.getValue('flow');
if(flows.indexOf(flow)>-1) continue;
flows.push(flow);
}
It's very likely that a flow may have multiple actions updating incidents (particularly those with branching logic) so we want to try and de-duplicate the list. (this code can be much simpler using modern JavaScript features but for compatibilities sake I'll keep it safe for now)
I hope you've enjoyed looking under the hood of flows, there is complexity there, and it's may take a while for it to all make sense, but there are still reasonable ways of finding the information you need if you invest a little bit of curiosity into a problem.
- 4,409 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
