ServiceNow Virtual Agent Scripts

  • Plugins Required:
    • Glide Virtual Agent 
    • Human Resources Scoped App: Virtual Agent Conversations

  • Chat history
    Opening the Virtual Agent with/without the chat history is possible. Just by adding "sysparm_skip_load_history=true" to the URL, the history will not be loaded. You can add this to the options of the widget, directly in the server script of a (cloned) widget, or if you calling the virtual agent separately through URL.

    https://<your-instance>.service-now.com/$sn-va-web-client-app.do? sysparm_nostack=true&sysparm_stack=no&sysparm_skip_load_history=true

  • Get global search text:
    vaSystem.getSearchText();

  • Reset Current Topic: 
    (function execute() {
    vaVars._topic_current = null;
    })()

  • Show topics:
    (function execute() {
    vaSystem.switchTopic(vaVars._setup_explore_help_topic);
    })()

  • Wait 10 seconds
    (function execute() {
    var dt = new Date();
    dt.setTime(dt.getTime() + 10000);
    while (new Date().getTime() < dt.getTime());
    return '';
    })()

  • Portal:
    (function execute() {
    return vaSystem.portal || new sn_hr_sp.hr_TicketPageConfigUtil().getActivePortalURLSuffix();
    })()

  • HR Service ID:
    (function execute() {
    return hr_ChatbotUtils.GENERAL_ENQUIRY_SERVICE_ID;
    })()

  • Global search text:
    (function execute() {
    return gs.nil(vaVars.global_search_text)
    })()
    (function execute() {
    return !gs.nil(vaVars.global_search_text)
    })()

  • Discover topic
    (function execute() {
    vaSystem.topicDiscovery();
    })()

  • Pre-chat executed
    (function execute() {
    return vaVars.global_preChatExecuted;
    })()
    (function execute() {
    return !vaVars.global_preChatExecuted;
    })()

  • Get Greeting Message
    (function execute() {
    vaVars.greeting_message = vaSystem.getGreetingMessage();
    })()

  • Current topic in Virtual Agent
    (function execute() {
    return JSON.parse(vaVars._topic_current).name;
    })()
    //Output
    {"sys_id":"79ce168ddb4a88d0b9f39026db9619cc", "task":"62a63689dbca88d0b9f39026db96199a", "name":"Test Switch Child", "title":"Test Switch Child", "type":"normal","utterance":""}


  • var search_term = vaInputs.search_term;
    var context = vaVars.search_context_sys_id;
    var contextualSearch = new sn_itsm_va.VAContextualSearchUtil();
    var response = contextualSearch.search(context, search_term);
    var success =contextualSearch.processSearchResponse(response); More references:
  • https://community.servicenow.com/community?id=community_question&sys_id=efcb8d1ddb5ff704414ed0c5ca96197d
  • https://community.servicenow.com/community?id=community_article&sys_id=a70b286cdb90e410f21f5583ca961967