How to show incident records created or updated within a selected timeframe using Virtual Agent?

SK07
Tera Contributor

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!

 
1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

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.

 

AniketChavan_0-1753796315558.png

 

 

AniketChavan_1-1753796393628.png

 

 

Final Output:

AniketChavan_3-1753796556736.png

 

 

Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024

 

 

View solution in original post

6 REPLIES 6

Hi @Aniket Chavan ,

Thanks so much for your help! I really appreciate it.

@SK07 Glad to know it helped and resolved your query!

Thanks a lot for marking my response as helpful and accepting the solution too 😉