- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 09:28 AM
Hi experts!
Please help me in fetching user last selected topic/promoted topic in virtual agent servicenow.
so that the returned value is populated to the short description of incident.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 11:28 AM
Hi @Hemachithra ,
Hope you are doing great.
To fetch the user's last selected topic/promoted topic in ServiceNow Virtual Agent and populate it to the short description of an incident, we can follow these steps:
- Create a Business Rule in ServiceNow that triggers when a new incident is created.
- In the Business Rule, use a GlideRecord query to retrieve the last selected topic/promoted topic from the Virtual Agent session history for the user.
- Update the short description field of the newly created incident with the fetched topic.
Reference code in BR :
// Business Rule: Fetch and Populate Last Selected Topic
// Table: Incident
(function executeRule(current, previous /*, displayed*/ ) {
// Check if the current incident has a virtual agent session ID associated with it
if (current.virtual_agent_session && current.virtual_agent_session.length > 0) {
// Query the Virtual Agent session history table to retrieve the last selected topic/promoted topic
var vaSessionHistory = new GlideRecord('sn_va_session_history');
vaSessionHistory.addQuery('session_id', current.virtual_agent_session);
vaSessionHistory.addQuery('topic', 'ISNOTEMPTY'); // Ensure we get only records with a topic (not system messages)
vaSessionHistory.orderByDesc('sys_created_on'); // Order by creation time in descending order
vaSessionHistory.setLimit(1); // Limit the result to the latest record
if (vaSessionHistory.next()) {
// If a session history record is found, update the incident's short description with the topic
current.short_description = vaSessionHistory.topic;
current.update();
}
}
})(current, previous);
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 11:28 AM
Hi @Hemachithra ,
Hope you are doing great.
To fetch the user's last selected topic/promoted topic in ServiceNow Virtual Agent and populate it to the short description of an incident, we can follow these steps:
- Create a Business Rule in ServiceNow that triggers when a new incident is created.
- In the Business Rule, use a GlideRecord query to retrieve the last selected topic/promoted topic from the Virtual Agent session history for the user.
- Update the short description field of the newly created incident with the fetched topic.
Reference code in BR :
// Business Rule: Fetch and Populate Last Selected Topic
// Table: Incident
(function executeRule(current, previous /*, displayed*/ ) {
// Check if the current incident has a virtual agent session ID associated with it
if (current.virtual_agent_session && current.virtual_agent_session.length > 0) {
// Query the Virtual Agent session history table to retrieve the last selected topic/promoted topic
var vaSessionHistory = new GlideRecord('sn_va_session_history');
vaSessionHistory.addQuery('session_id', current.virtual_agent_session);
vaSessionHistory.addQuery('topic', 'ISNOTEMPTY'); // Ensure we get only records with a topic (not system messages)
vaSessionHistory.orderByDesc('sys_created_on'); // Order by creation time in descending order
vaSessionHistory.setLimit(1); // Limit the result to the latest record
if (vaSessionHistory.next()) {
// If a session history record is found, update the incident's short description with the topic
current.short_description = vaSessionHistory.topic;
current.update();
}
}
})(current, previous);
Regards,
Riya Verma