Virtual Agent Topic Block: Wait N Seconds
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
| What is shared in this article, might not be best practice. Just sharing this to explore possibilities, find openings in ServiceNow, and have a mindset that your imagination is your limitation. |
|---|
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."
Wait N Seconds
I don't use this though often, though do like the concept: Having a possibility to 'pause' the topic for a few seconds. There is no out-of-the-box utility for this, so we do need to script this. I also tried with simpler methods like gs.sleep(), though no luck there.
So are you going to script this in all of your Topics, maybe even several times in a Topic, or are you going to make this more generic? Using a Script Include or… reusable Topic Blocks!
If we would script a wait, we could use something like:
var seconds = 1;
var date_time = new Date();
date_time.setTime(date_time.getTime() + (1000 * parseInt(seconds)));
while(new Date().getTime() < date_time.getTime());
Translating this into Virtual Agent script:
(function execute() {
var date_time = new Date();
date_time.setTime(date_time.getTime() + (1000 * parseInt(vaInputs.seconds)));
while(new Date().getTime() < date_time.getTime());
})()
Added a vaInputs for the seconds. vaInputs because we could easily use this as a mandatory Input Parameter on the Topic Block.
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 simply be the number of seconds the Wait should last.
The ultimate result would be that adding a wait for a specified number of seconds, now is just limited to a drag and droppable Utility on which you only have to select the Topic Block name and add an integer value for the number of seconds. Highly reusable, maintainable, no scripting anymore, etc..
Share
An Update Set with this Topic Block can be downloaded from Share:
- Virtual Agent Topic Block: Wait N Seconds
---
And that's it actually. Hope you like it. If any questions, remarks or other ideas for Topic Blocks, let me know!
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Quint Technology
1x ServiceNow Developer MVP
1x ServiceNow Community MVP
---
Labels:
https://www.servicenow.com/community/virtual-agent-nlu-articles/virtual-agent-topic-block-wait-n-seconds/ta-p/2311277
