Print List view of record with g_modal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2024 08:52 AM
Hello Team,
I need to print the list of incident as a modal in SOW when we select caller from caller field in an incident form,
i am new to SOW , Please guide me to help this issue resolved

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2024 09:59 PM
Hey @ABC6 any specific reason you want to use g_modal ? why not use declarative actions ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2024 11:16 PM
beacause i did implemented with g_modal by refering one community article of Ashly Snider and it get works , ut i dont want specific field i want to print whole list view and with the declarative action it is going to be too much complex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2024 10:51 PM
Hi @ABC6
you need to create a new client script and script include.
Step 1: Create a Onchange client script.
Table : incident
Field Name: Caller
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('GetCallerIncidents');
ga.addParam('sysparm_name', 'getIncidentsForCaller');
ga.addParam('sysparm_caller_id', newValue);
ga.getXMLAnswer(function(answer) {
var incidents = JSON.parse(answer);
if (incidents.length > 0) {
// Construct HTML for modal content
var modalContent = '<table><tr><th>Incident Number</th><th>Short Description</th></tr>';
incidents.forEach(function(incident) {
modalContent += '<tr><td>' + incident.number + '</td><td>' + incident.short_description + '</td></tr>';
});
modalContent += '</table>';
// Display the modal
var modal = new GlideModal();
modal.setTitle('Related Incidents');
modal.setBody(modalContent, false); // false to not automatically escape HTML
modal.render();
} else {
alert("No related incidents found for this caller.");
}
});
}
Step 2: Create a Script Include
Name : GetCallerIncidents
Client callable is true
var GetCallerIncidents = Class.create();
GetCallerIncidents.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncidentsForCaller: function() {
var callerId = this.getParameter('sysparm_caller_id');
var incidentsArray = [];
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', callerId);
gr.query();
while (gr.next()) {
var incident = {};
incident.number = gr.number.toString();
incident.short_description = gr.short_description.toString();
incidentsArray.push(incident);
}
return JSON.stringify(incidentsArray);
}
});
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2024 11:17 PM
it is not working for Service operation Workspace