<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide">
<g:evaluate var="jvar_tasktypes" object="true" jelly="true">
var incidents = [];
var gr = new GlideRecord('incident');
gr.addQuery('short_description', ''); // Filter incidents with an empty short_description
gr.orderBy('number');
gr.setLimit(5); // Limit the number of records for display (optional)
gr.query();
while (gr.next()) {
incidents.push({
sys_id: gr.getUniqueValue(),
number: gr.getValue('number')
});
}
incidents;
</g:evaluate>
<div class="container">
<div class="col-md-3">
<div class="panel-body">
<h4>Select an Incident</h4>
<select id="filter_task_type" class="form-control" onchange="filterTaskType()">
<option value="">-- Select Incident --</option>
<j:forEach var="jvar_tasktype" items="${jvar_tasktypes}">
<option value="${jvar_tasktype.sys_id}">${jvar_tasktype.number}</option>
</j:forEach>
</select>
</div>
</div>
<div class="col-md-9">
<div class="panel-body">
<h3>Incident Details</h3>
<div id="incDetails">
<div class="list-group">
<p>Select an incident to view details.</p>
</div>
</div>
</div>
</div>
</div>
<script>
function filterTaskType() {
var taskType = document.getElementById('filter_task_type').value;
console.log("Selected task type (sys_id): " + taskType); // Debugging the selected sys_id
var incDetails = document.getElementById('incDetails').querySelector('.list-group');
incDetails.innerHTML = '<p>Loading...</p>'; // Display loading text
if (!taskType) {
incDetails.innerHTML = '<p>Please select an incident.</p>';
return;
}
// GlideAjax call (ensure the Script Include method is correct in ServiceNow)
var ga = new GlideAjax('BillingInfoUtil'); // The Script Include must be named 'BillingInfoUtil'
ga.addParam('sysparm_name', 'getIncidentDetails'); // Ensure the method name is correct in your Script Include
ga.addParam('sysparm_task_type', taskType);
ga.getXMLAnswer(function(response) {
console.log("Raw Response: ", response); // Debugging the raw response
try {
var result = JSON.parse(response);
console.log("Parsed result: ", result); // Log the parsed result
if (result.error) {
incDetails.innerHTML = '<p>' + result.error + '</p>';
return;
}
var details = result; // Assume result contains the details object directly
console.log("Incident details: ", details); // Debugging the fetched details
// Check if details.number exists
if (!details.number) {
console.error("No number field found in incident details.");
incDetails.innerHTML = '<p>Incident number not found.</p>';
return;
}
// Dynamically generate the HTML to display incident details with a tab-like spacing
var html = `
<div class="list-group-item">
<p><strong>Number:</strong>    ${details.number || 'N/A'}</p>
</div>
<div class="list-group-item">
<p><strong>Short Description:</strong>    ${details.short_description || 'N/A'}</p>
</div>
<div class="list-group-item">
<p><strong>State:</strong>    ${details.state || 'N/A'}</p>
</div>
<div class="list-group-item">
<p><strong>Description:</strong>    ${details.description || 'N/A'}</p>
</div>
<div class="list-group-item">
<p><strong>Priority:</strong>    ${details.priority || 'N/A'}</p>
</div>
<div class="list-group-item">
<p><strong>Caller:</strong>    ${details.caller_id || 'N/A'}</p>
</div>
<div class="list-group-item">
<p><strong>Assigned To:</strong>    ${details.assigned_to || 'N/A'}</p>
</div>
<div class="list-group-item">
<p><strong>Created On:</strong>    ${details.created_on || 'N/A'}</p>
</div>`;
incDetails.innerHTML = html;
} catch (e) {
incDetails.innerHTML = '<p>An error occurred while processing the response.</p>';
console.error("Error parsing response: ", e);
}
});
}
</script>
</j:jelly>

OUTPUT:

Please help me to get incident details.