how to fetch webpage param to virtual agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2023 06:17 AM
I want access GUI param in vitual agent topics

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2023 07:03 AM
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:
-
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".
-
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.
-
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');
- 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
---------------
Regards,
Rajesh Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2023 08:24 AM
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