- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 05:10 AM
Hi Community,
I’m trying to build a Virtual Agent topic using VA Designer (Xanadu version) that helps users retrieve incident records created or updated in a specific timeframe.
Here’s what I want the bot to do:
Ask the user how far back they want to look (e.g., last 5 days, last 10 days, last 15 days, or let them pick a custom date)
Based on their selection, query the incident table and filter records using sys_created_on or sys_updated_on
Then display the matching records to the user—ideally in a table or cards inside the chat
I'm starting this from scratch and could use some guidance on how to set this up in VA Designer. Specifically:
How do I structure the conversation flow?
How do I store user inputs (days or dates)?
What’s the best way to use GlideRecord in Scripted Actions for this?
And how do I present the results in a clean, interactive way?
Any help or examples would be amazing. Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 06:43 AM
Hello @SK07 ,
Just got some time to replicate your use case and wanted to share a simple working example I tried in my PDI—it should help you get started quickly.
I kept this in a separate topic and structured it in two main steps:
🔹 Step 1 – Ask user for timeframe
Create a text question (open-ended input) like:
"How many days back do you want to check for incidents?"
-
Variable Name: "get_days_range"
-
Input Format: Text (you can later enhance it to use quick replies like 5, 10, 15, etc.)
🔹 Step 2 – Scripted Table Response
Use the "Table" response type to display incidents in a clean tabular format.
Here’s the script I used inside the table’s Populate with Script section:
(function execute(table) {
var daysRange = parseInt(vaInputs.get_days_range);
var userId = gs.getUserID(); // Logged-in user
// Relative date filter (X days ago)
var relativeDate = '@dayofweek@ago@' + daysRange;
// Encoded query to fetch created or updated incidents
var encodedQuery = 'caller_id=' + userId +
'^NQsys_created_onONRELATIVEGE' + relativeDate +
'^ORsys_updated_onONRELATIVEGE' + relativeDate;
var gr = new GlideRecordSecure(table);
gr.addEncodedQuery(encodedQuery);
gr.query();
return gr;
})(table);
In the Columns section of the table, I displayed:
-
Number
-
Assigned to
-
State
Feel free to adjust based on your needs.
Final Output:
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 05:23 AM
what did you start with?
1) ask user the days using pre-defined choices
2) once user gives that then use GlideRecord and encoded query and bring the INCs
3) then present those using Card Response or HTML Response
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 05:28 AM
Hello @SK07 ,
Before diving into the implementation, I just wanted to clarify one thing—how are you planning to run this conversation? Will this be part of your main Greeting Topic where you directly ask the user how far back they want to check? Or are you planning to keep this functionality in a completely separate topic where the user selects it from the topic list?
If it’s a standalone topic, your first user question could simply be something like:
“How many days back do you want to check for incidents?”
Here, users can enter numbers like 5, 10, or 15—so I’d treat this as an open-ended input (Integer type) rather than fixed choices, unless you want to guide them using quick replies.
Once you have that number input from the user, you can use it directly in your Script step and form a dynamic encoded query , depending on your use case.
If I get some free time later today or in the next few hours, I’ll try replicating your exact use case in my PDI and share a working example or overview here. But till then, I’d say go ahead and try it out.....
🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 06:24 AM
Hi @SK07 ,
🔧 User Input: How far back to look
Use a Multiple Choice User Input Node:
Label: "How far back do you want to check for incident records?"
Options:
Last 5 days → value: 5
Last 10 days → value: 10
Last 15 days → value: 15
Custom Date Range → value: custom
→ Store this in variable: time_range
If Custom Date, Ask for From/To Dates
Add a Condition Node:
If time_range == custom → Ask two Date User Inputs:
"Enter start date" → store in start_date
"Enter end date" → store in end_date
Scripted Action: Query Incidents
Use a Script Block (Scripted Action). Create one Scripted Action named: GetIncidentRecordsByTimeRange.
📌 Inputs to Scripted Action:
time_range (string)
start_date (optional, date)
end_date (optional, date)'
(function execute(inputs, outputs) {
var gr = new GlideRecord('incident');
var daysBack = parseInt(inputs.time_range);
if (isNaN(daysBack)) {
// Custom Date Range
gr.addQuery('sys_updated_on', '>=', inputs.start_date);
gr.addQuery('sys_updated_on', '<=', inputs.end_date);
} else {
var now = new GlideDateTime();
var pastDate = new GlideDateTime();
pastDate.addDaysUTC(-daysBack);
gr.addQuery('sys_updated_on', '>=', pastDate);
}
gr.orderByDesc('sys_updated_on');
gr.setLimit(10); // Display max 10 incidents
gr.query();
var incidents = [];
while (gr.next()) {
incidents.push({
number: gr.getValue('number'),
short_description: gr.getValue('short_description'),
state: gr.getDisplayValue('state'),
updated: gr.getDisplayValue('sys_updated_on'),
sys_id: gr.getUniqueValue()
});
}
outputs.incident_list = incidents;
})(inputs, outputs);
Output Variable: incident_list (Array)
And at the end use cards to output what u want
Thanks and regards
Nitya Bansal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2025 06:43 AM
Hello @SK07 ,
Just got some time to replicate your use case and wanted to share a simple working example I tried in my PDI—it should help you get started quickly.
I kept this in a separate topic and structured it in two main steps:
🔹 Step 1 – Ask user for timeframe
Create a text question (open-ended input) like:
"How many days back do you want to check for incidents?"
-
Variable Name: "get_days_range"
-
Input Format: Text (you can later enhance it to use quick replies like 5, 10, 15, etc.)
🔹 Step 2 – Scripted Table Response
Use the "Table" response type to display incidents in a clean tabular format.
Here’s the script I used inside the table’s Populate with Script section:
(function execute(table) {
var daysRange = parseInt(vaInputs.get_days_range);
var userId = gs.getUserID(); // Logged-in user
// Relative date filter (X days ago)
var relativeDate = '@dayofweek@ago@' + daysRange;
// Encoded query to fetch created or updated incidents
var encodedQuery = 'caller_id=' + userId +
'^NQsys_created_onONRELATIVEGE' + relativeDate +
'^ORsys_updated_onONRELATIVEGE' + relativeDate;
var gr = new GlideRecordSecure(table);
gr.addEncodedQuery(encodedQuery);
gr.query();
return gr;
})(table);
In the Columns section of the table, I displayed:
-
Number
-
Assigned to
-
State
Feel free to adjust based on your needs.
Final Output:
Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024