Virtual Agent Topic Block: Start Subflow (Flow Des... - ServiceNow Community
Mark Roethof
Tera Patron
Tera Patron

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

There is a newer version available for this content: "Triggering Flow Designer subflows/actions through Virtual Agent

 

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:

 

find_real_file.png

 

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).

 

find_real_file.png

 

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.

 

find_real_file.png

 

For Synchronous Subflows, the possible output returned will also be available:

 

find_real_file.png

 

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!

 

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?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Consultant @ Quint Technology

1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

Comments
Eric M
Giga Expert

very smart idea. i hear they are fixing some of this in the upcoming release 

josjordan
Tera Contributor

Looks like I am the 24th person to download this and not much information on getting it to work - Any of the other 23 people following this article?  

Anyone get the update set to work?

Mark Roethof
Tera Patron
Tera Patron

Hi there,

What is it that you are missing?

Also note, while this article was written it was a valid topic block. Though with Quebec, this topic block is obsolete because of the new out-of-the-box function.

Kind regards,
Mark

josjordan
Tera Contributor

That is my problem..  The topic block is non-existent...  Hmmm  New out of the box function?   I must be missing an update..   

I just checked and Virtual Agent Designer appears to be up to date ?

This is our DEV system so I would not doubt we are behind in something - Any pointers as to what we might be deficient in?

Oh - Maybe the update is not yet available to the FEDRAMP world?

Not sure if this helps:

Build name: Paris
Build date: 05-04-2021_2116
Build tag: glide-paris-06-24-2020__patch7b-04-26-2021
Instance name: xxxxxx
Instance ID: xxxxx
Node ID: xxxx
IP address: xx.xx.xx.xx
MID buildstamp: paris-06-24-2020__patch7b-04-26-2021_05-04-2021_2116
Load-balancer status: Online
Database latency: 0
Offering: enterprise

 

Thanks so much for the prompt response!  --joe

Mark Roethof
Tera Patron
Tera Patron

 

"Build name: Paris"

I mentioned, that's there's a new function where this is out of the box with Quebec 🙂

Kind regards,
Mark

josjordan
Tera Contributor

You just pointed out my inability to read...   We are still on Paris in DEV -  Quebec is still a bit off for us....

Thanks again for the time and assistance.   I will have to do manually and revisit at a later date...  --joe

 

Version history
Last update:
‎08-18-2024 06:31 AM
Updated by:
Contributors