Virtual agent

HARSHA GOWDA R
Tera Contributor

(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

3 REPLIES 3

palanikumar
Mega Sage

Hi,

Did you pass the correct table name in the actual script?

var userRoles = new GlideRecord('table name');

Thank you,
Palani

Yes

palanikumar
Mega Sage

Instead of gs.getUserID(), try vaInputs.user or vaInputs.user.sys_id

Thank you,
Palani