function Onload () {
var callerfield = g_form.getControl ('u_caller_name'); < /p>
Код: Выделить всё
if (callerField) {
var icon = document.createElement('span');
icon.innerHTML = '📜'; // History icon
icon.style.cursor = 'pointer';
icon.style.marginLeft = '10px';
icon.title = 'View Incident History';
icon.onclick = function () {
showIncidentHistory();
};
callerField.parentNode.appendChild(icon);
}
< /code>
} < /p>
function showincidenthistory () {
var username = g_form.getValue ('u_caller_name'); < /p>
if (!userName) {
alert("Please select a user first.");
return;
}
var ga = new GlideAjax('IncidentHistoryAjax');
ga.addParam('sysparm_name', 'getHistory');
ga.addParam('sysparm_user', userName);
ga.getXMLAnswer(function(response) {
if (!response) {
alert("No incident history found.");
return;
}
var historyData = JSON.parse(response);
var historyHTML = "NumberShort DescriptionStateCreated";
if (historyData.length === 0) {
historyHTML += "No past incidents found.";
} else {
historyData.forEach(function(record) {
historyHTML += `
${record.number}
${record.short_description}
${record.state}
${record.created}
`;
});
}
historyHTML += "";
var modal = new GlideModal('Incident History');
modal.setTitle('Incident History for ' + userName);
modal.setBody(historyHTML, false, false);
modal.render();
});
Подробнее здесь: https://stackoverflow.com/questions/795 ... w-platform