logo

NJP

Virtual Agent - Enhanced Check Ticket Status topic

Import · Apr 07, 2019 · article

Hi there,

While the out-of-the-box Check IT Ticket Status ITSM Conversation for the Virtual Agent is a rather small topic, it could potentially provide users with a valuable topic. So how can we raise the level of this conversation?Some thoughts and experiences here to share with you.

Check Ticket Status instead of Check IT Ticket Status

First and foremost thing which is limiting the out-of-the-box topic: It only is about Incidents and Requested Items. Though what if you also want to know the status of Changes? Facility Requests? Stories? Or you've added a custom process, and you want to implement those tickets as well? The out-of-the-box Check IT Ticket Status topic, unfortunately, does not offer room to easily add different processes. Everything is hardcoded.

What we came up with, upon configuring the Check Ticket Status topic, a Script Variable "ticket_options" holds all information about the processes to support. Most imported coding being:

    var options = [];
    options.push(
    {
        "table":"incident",
        "query":"active=true^caller_id=" + gs.getUserID(),
        "fields": [
            {"name":"short_description"},
            {"name":"state"}
        ],
        "comments":"comments"
    });
    options.push(   
    {
        "table":"sc_req_item",
        "query":"active=true^request.requested_for=" + gs.getUserID(),
        "fields": [
            {"name":"cat_item"},
            {"name":"state"}
        ],
        "comments":"comments"
    });
    options.join();

    return JSON.stringify(options);

If for example, you just want to expand the topic with Change Request. Only code additional needed in this Script Variable:

    options.push(
    {
        "table":"change_request",
        "query":"active=true^u_requested_for=" + gs.getUserID(),
        "fields": [
            {"name":"short_description"},
            {"name":"state"}
        ],
        "comments":"comments"
    });
    options.join();

The Script Variable ticket_options is utilized thru out the whole topic. Already the first step, which is showing the active tickets created by the user. Instead of hardcoded steps, the Script Variable is parsed and generated an overview.

    vaVars.index = 0;

    var optionsObj = JSON.parse(vaVars.ticket_options);
    var countInt = 0;

    for(i = 0; i < optionsObj.length; i++) {
        var gaTable = new GlideRecord('sys_documentation');
        gaTable.addQuery('name', optionsObj[i].table);
        gaTable.addNullQuery('element');
        gaTable.addQuery('language', 'en');
        gaTable._query();

        if(gaTable._next()) {
            optionsObj[i].label = gaTable.getValue('label');
            optionsObj[i].plural = gaTable.getValue('plural');
        }

        var gaTable = new GlideAggregate(optionsObj[i].table);
        gaTable.addEncodedQuery(optionsObj[i].query);
        gaTable.addAggregate('COUNT');
        gaTable._query();

        if(gaTable._next()) {
            if(gaTable.getAggregate('COUNT') > 0) {
                optionsObj[i].count = gaTable.getAggregate('COUNT');

                countInt = countInt + parseInt(optionsObj[i].count);
            } else {
                delete optionsObj[i];
            }
        }
    }

    vaVars.ticket_details = JSON.stringify(optionsObj);
    vaVars.ticket_details = vaVars.ticket_details.replaceAll(',null', '');

    vaVars.ticket_count = countInt;

Notice there is a "count" mentioned in this code, in the previous step, this has been added and represents the number of active tickets for this table.

Type of tickets and tickets for table selected

Based on the results, the topic ends or proceeds with defining which type of tickets to check. If a user has only active incidents, defining which tickets to check is automatically set to incidents.

The actual displaying of the type of tickets and tickets for the table selected is a very similar setup. Though again, dynamically done instead of hardcoded.

The "Next page" and "Previous page" options from the out-of-the-box Check IT Ticket Status topic is very solid. We just kept them image

Number of tickets given in the choice list

You might wonder why out-of-the-box, only up to 5 tickets are displayed. The reason is pretty simple: the GlideRecord query gets a number which is set in Script Variable "limit". Out-of-the-box, this Script Variable is set to 5.

gr.chooseWindow(index, index + limit, true);

Exit choice list

We only added one option, is if the user wants to break out of the flow, made a wrong choice, etc.. The Virtual Agent does not offer such functionality, only having "New Conversation" under the More options.

Display record

The out-of-the-box Check IT Ticket Status Script Output Bot Responses "Display *" have a hardcoded link to the Platform UI. Be aware of this, you might want to alter this.

url: vaVars.base_url + vaVars.service_portal_base_url + '?sys_id=' + gr.getUniqueValue() + '&amp;view=sp&amp;id=ticket&amp;table=incident',

Add comment

Also, the "Add comment" functionality is pretty solid. We kept this with just one adjustment: a check on the user input if it empty or not. While checking if the user input it is empty, we've chosen to do this Low Code and not No Code. With No Code, for example, a space as user input is accepted, while with Low Code we could trim the user input.

    return vaInputs.enter_comment.getValue().trim() == '';

Dynamic Bot responses

To give the Bot a bit more variety, and because this is a more often used topic, we decided to have some dynamic bot responses. Not that hard to achieve, just add some Low Code to the Response Message.

image

    var conditionStr = Math.floor(Math.random() * 2) + 1;

    switch(conditionStr) {
        case 1:
            return gs.getMessage('Give me a micro sec while I\'ll get you that record.');
            break;
        default:
            return gs.getMessage('Tough cookie, though found it.');
    }

Chat satisfaction survey

And of course, at the end of the conversation, we've implemented our chat satisfaction topic. The chat satisfaction topic is explained in this community article.

image

Summary

The out-of-the-box Check IT Ticket Status topic does offer a solid base to start with. Though, with some slight adjustments, you could enhance the topic greatly!

image

---

Hope that this helps some of you! Questions or ideas? Let me know!

image If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful.Interested in more articles, blogs, videos, and Share projects on Virtual Agent I published?- Virtual Agent

Kind regards,

Mark

---

LinkedIn

image

View original source

https://www.servicenow.com/community/virtual-agent-nlu-articles/virtual-agent-enhanced-check-ticket-status-topic/ta-p/2298810