how to fetch webpage param to virtual agent

Community Alums
Not applicable

I want access GUI param in vitual agent topics

2 REPLIES 2

Rajesh_Singh
Kilo Sage
Kilo Sage

Fetching webpage parameters in ServiceNow Virtual Agent can be done using client-side JavaScript and passing the value to the Virtual Agent through user input or as a hidden value. Here's a step-by-step process to achieve this:

  1. Create a new variable on the Virtual Agent Designer for the parameter you want to pass from the webpage. For example, let's say you want to pass a "pageID" parameter. In the Virtual Agent Designer, create a variable called "pageID".

  2. Add a "User Input" node in your Virtual Agent conversation flow to capture the "pageID" value. Set the "Variable" field to the "pageID" variable you created earlier.

  3. In the webpage where the Virtual Agent is embedded, add JavaScript code to fetch the parameter value from the URL. For example, you can use the following JavaScript function to get the "pageID" parameter value:

    function getURLParameter(name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
    }
    
    var pageID = getURLParameter('pageID');
    



  4. To pass the "pageID" value to the Virtual Agent, you need to interact with the ServiceNow Virtual Agent client-side API. Here's an example of how to do this:
function setVirtualAgentVariable(variableName, value) {
    if (window.sn_va && window.sn_va.init_done) {
        window.sn_va
If you found my response helpful or applicable, please consider marking it as correct or helpful to assist others who may be seeking the same information.

---------------
Regards,
Rajesh Singh

Hi Rajesh,

 

I'm interested in the topic, but your solution seems to be incomplete: the step 4 it's only sketchy. Could you please fill the code, in order to make the example consistent?

 

Thanks in advance,

Giuseppe Cozza