Virtual Agent Topic Block: Start Subflow (Flow Designer)
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
With the Orlando release, ServiceNow introduced reusable Topic Blocks for Virtual Agent. Reusable components, which you could compare with Subflows or Actions. A really nice feature that helps build Topics smarter, faster, more consistent and manageable. Also less scripting knowledge is needed when working in Topics, because this logic has been set up in the Topic Block.
In a few short articles, I'll share some of the reusable Topic Blocks I've set up. These Topic Blocks can also be downloaded from Share.
Topic Blocks
A short recap:
Pre-Orlando
Basically pre-Orlando if we would have a repetitive group of steps for multiple Topics or even within a Topic, we simply had to duplicate them/build them over and over. There was no possibility to set up something like a Subflow. Well, maybe a small workaround would be doable for some situations, using vaSystem.switchTopic() or vaSystem.topicDiscovery().
Orlando
With the Orlando reusable a repetitive group of steps for multiple Topics or even within a Topic, can be placed within a "topic blocks". The short explanation of Topic Blocks according to the Docs site:
"A Topic block is basically a Subflow that performs certain actions or conversational tasks in a Topic."
Start Subflow (Flow Designer)
After working with Virtual Agent for a while, you might cross a point thinking "Can we technically smarten our Virtual Agent topics? Can we initiate or perform more complex operations?" Of course, we can! In one of my previous articles, I've described how you can tie Events, REST Messages, Flow Designer, Workflows to Virtual Agent:
Calling Events, REST, Flow Designer, Workflows through Virtual Agent
So let's go for Starting Subflows within Virtual Agent. Building it smarter, faster, more consistent and manageable: going for a Topic Block! First thing would be, what's the basic scripting to start subflows scripted? The updated method for the Paris-release looks something like:
var inputs = {};
inputs['current'] = current;
inputs['table_name'] = 'incident';
var result = sn_fd.FlowAPI
.getRunner()
.subflow('global.test_flow')
.inBackground()
.withInputs(inputs};
.run();
This example uses inBackground (Asynchronous), where you could also use inForeground (Synchronous).
So let's add an Input for Asynchronous / Synchronous, and above script into Virtual Agent script:
(function execute() {
var inputs = [];
if(inputs = JSON.parse(vaInputs.inputs) != '') {
inputs = JSON.parse(vaInputs.inputs);
}
// Asynchronous
if(vaInputs.asynchronous.getValue() == 'True' || vaInputs.asynchronous.getValue() == 'true') {
var result = sn_fd.FlowAPI
.getRunner()
.subflow(vaInputs.subflow_name.getValue())
.inBackground()
.withInputs(inputs)
.run();
return;
}
// Synchronous
if(vaInputs.asynchronous.getValue() == 'False' || vaInputs.asynchronous.getValue() == 'false') {
var result = sn_fd.FlowAPI
.getRunner()
.subflow(vaInputs.subflow_name.getValue())
.inForeground()
.withInputs(inputs)
.run();
vaVars.outputs = JSON.stringify(result.getOutputs());
return;
}
})()
At the start of the script, a JSON input has been added. This can be read and used within the Subflow.
For the Synchronous part, I've also added an output. Since the Subflow can provide output while running Synchronous
The output is also in JSON format.
Result
Above steps would result in a short Topic Block like:
Now we can simply use this Topic Block in Topics using the Topic Block utility.
The Topic Block Properties would ask you to supply seconds (mandatory). This would be the Internal name of the Subflow, any inputs (in JSON format) and a true/false value concerning if the Subflow should run Asynchronous (true) or Synchronous (false).
Below an example script for the Inputs input, which would provide a sys_id to the Subflow.
(function execute() {
var inputs = {
'sysid' : '9d385017c611228701d22104cc95c371'
};
return JSON.stringify(inputs);
})()
Within the subflow, you could just define your inputs which correspond to above script.
For Synchronous Subflows, the possible output returned will also be available:
The ultimate result would be that starting a Subflow from Virtual Agent, now is just limited to a drag and droppable Utility on which you only have to select the Topic Block name and add the inputs. Highly reusable, maintainable, no scripting anymore, etc..
Share
An Update Set with this Topic Block can be downloaded from Share:
- Virtual Agent Topic Block: Start Subflow (Flow Designer)
---
And that's it actually. Hope you like it. If any questions, remarks or other ideas for Topic Blocks, let me know!
Kind regards,
Mar k Roethof
ServiceNow Technical Consultant @ Quint Technology
1x ServiceNow Developer MVP
1x ServiceNow Community MVP
---
https://www.servicenow.com/community/virtual-agent-nlu-articles/virtual-agent-topic-block-start-subflow-flow-designer/ta-p/2311240
