Virtual agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2024 10:50 PM
This code i have written in table form bot response in virtual agent.This is giving me the correct output currently its giving me in this format
But i need access and endpoint should come in separate column,below i have pasted the reference of it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2024 11:13 PM
Try the below Script
function execute() {
// Define column headers
var headers = ['Access', 'Endpoint'];
var rows = []; // Array to hold row values
var userRoles = new GlideRecord('tablename');
userRoles.addQuery('directory.servicenow_id', gs.getUserID());
userRoles.addQuery('stage', '=', 'granted'); // Ensure the 'stage' field is correct
userRoles.orderBy("iam_roles.application");
userRoles.query();
while (userRoles.next()) {
// Get values for 'Access' and 'Endpoint' columns
var access = userRoles.getDisplayValue('iam_roles');
var endpoint = userRoles.getDisplayValue('iam_roles.application');
// Push each role and application as a separate row
rows.push([access, endpoint]);
}
// Return the table structure
return {
columnHeaders: headers, // Column headers for the table
columnValues: rows // Row values for the table
};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2024 11:26 PM
Hi @Ravi Gaurav
Its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2024 11:29 PM
Hi @HARSHA GOWDA R
I added a log /info can you tell me the output of that
function execute() {
var headers = ['Access', 'Endpoint'];
var rows = [];
// Create a GlideRecord to query the relevant table
var userRoles = new GlideRecord('tablename');
userRoles.addQuery('directory.servicenow_id', gs.getUserID());
userRoles.addQuery('stage', '=', 'granted');
userRoles.orderBy("iam_roles.application");
userRoles.query();
// Loop through each result and push values into rows
while (userRoles.next()) {
// Get values for Access and Endpoint columns
var access = userRoles.getDisplayValue('iam_roles'); // Access value
var endpoint = userRoles.getDisplayValue('iam_roles.application'); // Endpoint value
// Log values for debugging
gs.info("Access: " + access + ", Endpoint: " + endpoint);
// Push the row into the array
rows.push([access, endpoint]);
}
// Log rows array for verification
gs.info("Rows Array: " + JSON.stringify(rows));
// Return the table structure for Virtual Agent
return {
columnHeaders: headers,
columnValues: rows
};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2024 11:36 PM