Assistance Needed with Redirecting to Bar Chart Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 01:06 AM
Hello,
I successfully created a button in the list action that redirects to a pie chart report when "Pie Chart" is selected. I would like to achieve the same functionality for the "Bar Chart" option. Despite trying several methods, I haven't been successful. Could you please help me with this?
this is my code:
var checkIncident = new GlideAjax("ChoicesUtils");
checkIncident.addParam("sysparm_name", "getChoices");
checkIncident.getXMLAnswer(function(response) {
var answer = JSON.parse(response);
var choices = [];
for (var i = 0; i < answer.length; i++) {
choices.push({
displayValue: answer[i].label,
value: answer[i].value,
});
}
var fields = [{
type: 'choice',
name: 'details',
label: 'Group by:',
mandatory: true,
choices: choices
}];
var modalConfig = {
title: 'Incident Details',
fields: fields,
cancelTitle: "Bar Chart",
confirmTitle: "Pie Chart",
cancelType: "default",
size: "md",
confirmType: "confirm"
};
g_modal.showFields(modalConfig).then(function(fieldValues) {
if (fieldValues.updatedFields && fieldValues.updatedFields.length > 0) {
var firstField = fieldValues.updatedFields[0];
var currentQuery = g_list ? g_list.getQuery({ orderby: true }) : ''; // Adjust based on your context
if (firstField && firstField.value) {
var url = 'https://dev244597.service-now.com/sys_report_template.do?sysparm_field=' + encodeURIComponent(firstField.value) +
'&sysparm_type=pie&sysparm_table=incident&sysparm_from_list=true&sysparm_chart_size=large&sysparm_manual_labor=true&sysparm_query=' +
encodeURIComponent(currentQuery);
open(url, "_blank"); // This opens the URL in a new tab
} else {
alert("Field value is undefined. Check your script.");
}
} else {
var url = 'https://dev244597.service-now.com/sys_report_template.do?jvar_report_id=undefined';
open(url, "_blank");
}
});
});