How do I get the value of the entity?

rossida
Tera Contributor

I have an utterance: "Who does @employee work for?" The entity is Employee, so within my Topic flow, how do I get get the value of the entity???   Therefore, if I enter the following in the Virtual Agent:"who does John Doe work for?", I want the Topic is get just the entity's value: "John Doe".  HOW can I get this??

 

6 REPLIES 6

Abbas_5
Tera Sage
Tera Sage

Hello @rossida,

 

To get the value of an entity in ServiceNow, especially within the context of Virtual Agent or Natural Language Understanding (NLU), you typically access it through the vaVars object, specifically vaVars._topic_results which provides entity values in JSON format. 
 
Here's a breakdown of how to retrieve entity values:
1. Accessing the vaVars object:
  • In a Virtual Agent script or topic, you can access variables related to the conversation using vaVars.
  • vaVars._topic_results holds the results of the NLU processing, including identified entities. 
     
2. Extracting Entity Values:
  • vaVars._topic_results provides a JSON object. You need to parse this object to extract the specific entity value you're interested in.
  • The structure of this JSON object will depend on how the entity was defined and identified by NLU. 
     
Example:
 
Let's say you have an entity called "location" and you want to get its value. You might access it like this: 
 
JavaScript
(function execute() {  var locationValue = vaVars._topic_results.entities.location; // Assuming "location" is the entity name  gs.info("The location entity value is: " + locationValue);  return locationValue;})()

If this is helpful, please hit the thumbs up button and accept the correct solution by referring to this solution in future it will be helpful to them.

Thanks & Regards,

Abbas Shaik

mohammadabd
Tera Contributor
From "_topic_results" I can see only the "entities" names not the values associated to it.
 
[
    {
        "task": "4343a3d36465624bcb9b",
        "entities": "[\"ServerStorageRequestType\",\"HARDWARE\",\"HARDWARE\"]",
        "name": "_PRVW__34fg6255064dfab5f42e951846a39d",
        "title": "Test Entity Extract",
        "type": "normal",
        "utterance": "mainframe password reset",
        "prediction": "ServerStorage",
        "modelId": "ml_x_gesp_sn_itsm_nlu_global_5gdw8efb4752a6d0d66cf3e5536d4318",
        "sys_id": "567fg1851b2a2610a3d36465624bcb04"
    }
]

Thanks for the reply!

 

This is what I did:

- I created an Input variable called:

vaInputs.utterance_employeeValue

vaInputs.utteranceemployeeValue. This variable has the "NLU entity" set to "Employee". 

- I have have a "Bot response" component that is using the "Text Response" to display this value.  

 

I have 8 employee's with the name: "John Smith"
Virtual agent shows me 8 sys_ids but these sys_ids are NOT the USER-record sys_ids.  These are the Entity's sys_ids (I believe). 

How do I get and show all the entity values ?
For instance:
John A. Smith

John B. Smith

John C. Smith

John D. Smith

John E. Smith

John F. Smith

John G. Smith

John H. Smith

 

and have the user select which user they want??

rossida
Tera Contributor

Thanks for the reply!

 

This is what I did:

- I created an Input variable called: vaInputs.utterance_employeeValue. This variable has the "NLU entity" set to "Employee". 

- I have have a "Bot response" component that is using the "Text Response" to display this value.  Therefore, in the "Response message", I have vaInputs.utterance_employeeValue

 

I have 8 employee's with the name: "John Smith"
Virtual agent shows me 8 sys_ids but these sys_ids are NOT the USER-record sys_ids.  These are the Entity's sys_ids (I believe). 

How do I get and show all the entity values ?
For instance:
John A. Smith

John B. Smith

John C. Smith

John D. Smith

John E. Smith

John F. Smith

John G. Smith

John H. Smith

 

and have the user select which user they want??