Displaying Assets Of A User Through Virtual Agent

Noone1234567
Tera Contributor

Hello, 

 

I would like the virtual agent to display all the assets tagged to a user when the user enters their name in the virtual agent client. Is there a pre-defined way to do something similar to this? If not, what would be the conventional or industry standard way to add this new feature to the virtual agent?

1 ACCEPTED SOLUTION

DUGGI
Giga Guru

@Noone1234567 

 

To display all the assets tagged to a user when the user enters their name in the virtual agent client in ServiceNow, you can create a custom conversation flow in the Virtual Agent Designer.

Here are the steps you can follow:

  1. Create a new flow in the Virtual Agent Designer and name it "Display User Assets". This will capture the user's input and trigger the conversation flow.
  2. Create a new variable in the Virtual Agent Designer to capture the user's name. You can name the variable "user_name" and set its type to "string".
  3. Add a new question to the "Display User Assets" intent, and use the "Ask for Input" node to prompt the user to enter their name. In the response field, you can provide a message such as "Please enter your name to view your assets".
  4. Once the user provides their name, you can use a Script node to query the ServiceNow CMDB for assets assigned to the user. Here's an example script you can use:
// Query CMDB for assets assigned to user
var assets = [];
var user = new GlideRecord('sys_user');
user.addQuery('name', current.variables.user_name);
user.query();
if (user.next()) {
  var asset = new GlideRecord('alm_asset');
  asset.addQuery('assigned_to', user.sys_id);
  asset.query();
  while (asset.next()) {
    assets.push(asset.name);
  }
}

// Set response message based on query results
var response = '';
if (assets.length > 0) {
  response = 'The following assets are assigned to you: ' + assets.join(', ');
} else {
  response = 'No assets are assigned to you';
}

// Return response message to user
answer = response;

This script queries the ServiceNow CMDB for assets assigned to the user entered by the user, and returns a message listing the assets assigned to the user. If no assets are assigned to the user, it returns a message stating that no assets are assigned to the user.

  1. Add a "Send Response" node to the conversation flow to display the message to the user.
  2. Test the conversation flow in the Virtual Agent to verify that it displays the assets assigned to the user entered by the user.

This approach should allow you to display all the assets tagged to a user when the user enters their name in the virtual agent client.

View solution in original post

1 REPLY 1

DUGGI
Giga Guru

@Noone1234567 

 

To display all the assets tagged to a user when the user enters their name in the virtual agent client in ServiceNow, you can create a custom conversation flow in the Virtual Agent Designer.

Here are the steps you can follow:

  1. Create a new flow in the Virtual Agent Designer and name it "Display User Assets". This will capture the user's input and trigger the conversation flow.
  2. Create a new variable in the Virtual Agent Designer to capture the user's name. You can name the variable "user_name" and set its type to "string".
  3. Add a new question to the "Display User Assets" intent, and use the "Ask for Input" node to prompt the user to enter their name. In the response field, you can provide a message such as "Please enter your name to view your assets".
  4. Once the user provides their name, you can use a Script node to query the ServiceNow CMDB for assets assigned to the user. Here's an example script you can use:
// Query CMDB for assets assigned to user
var assets = [];
var user = new GlideRecord('sys_user');
user.addQuery('name', current.variables.user_name);
user.query();
if (user.next()) {
  var asset = new GlideRecord('alm_asset');
  asset.addQuery('assigned_to', user.sys_id);
  asset.query();
  while (asset.next()) {
    assets.push(asset.name);
  }
}

// Set response message based on query results
var response = '';
if (assets.length > 0) {
  response = 'The following assets are assigned to you: ' + assets.join(', ');
} else {
  response = 'No assets are assigned to you';
}

// Return response message to user
answer = response;

This script queries the ServiceNow CMDB for assets assigned to the user entered by the user, and returns a message listing the assets assigned to the user. If no assets are assigned to the user, it returns a message stating that no assets are assigned to the user.

  1. Add a "Send Response" node to the conversation flow to display the message to the user.
  2. Test the conversation flow in the Virtual Agent to verify that it displays the assets assigned to the user entered by the user.

This approach should allow you to display all the assets tagged to a user when the user enters their name in the virtual agent client.