Virtual agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2024 08:16 PM
(function execute() {
var roleObject = {};
var userRoles = new GlideRecord('table name');
userRoles.addQuery('directory.servicenow_id', gs.getUserID());
userRoles.addQuery('stage', '=', 'granted'); // Ensure the 'stage' field is correct
userRoles.orderBy("iam_roles.application");
userRoles.query();
// Start creating the HTML table
var htmlTable = '<table style="width: 100%; border-collapse: collapse;">';
htmlTable += '<thead><tr>';
htmlTable += '<th style="border: 1px solid #dddddd; padding: 8px; text-align: left;">Access</th>';
htmlTable += '<th style="border: 1px solid #dddddd; padding: 8px; text-align: left;">Endpoint</th>';
htmlTable += '</tr></thead><tbody>';
while (userRoles.next()) {
var roleID = userRoles.getDisplayValue('iam_roles');
var applicationName = userRoles.getDisplayValue('iam_roles.application');
// Add each role and application as a new row in the HTML table
htmlTable += '<tr>';
htmlTable += '<td style="border: 1px solid #dddddd; padding: 8px;">' + roleID + '</td>';
htmlTable += '<td style="border: 1px solid #dddddd; padding: 8px;">' + applicationName + '</td>';
htmlTable += '</tr>';
}
// Close the HTML table
htmlTable += '</tbody></table>';
// Set the HTML table as the output for the Virtual Agent
vaVars.Role_and_application_html = htmlTable;
})();
Above code is not working in my HTML bot response in Virtual agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2024 09:02 PM
Hi,
Did you pass the correct table name in the actual script?
var userRoles = new GlideRecord('table name');
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2024 09:06 PM
Yes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2024 09:14 PM
Instead of gs.getUserID(), try vaInputs.user or vaInputs.user.sys_id
Palani