Client Callable Script Include: var BillingInfoUtil = Class.create(); BillingInfoUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, { getBillingInfo: function(){ var taskType = this.getParameter('sysparm_task_type'); gs.log("Task Type: " + taskType, "Select EX") var gr = new GlideRecord("incident"); //this gliderecord setup is assuming you're expecting one record exists that meets the //criteria. Adjust if necessary gr.get(taskType); var fields = ['number','short_description','state'] var bu = {}; if (gr.getUniqueValue()){ //this is an assumption. You'll need to determine what your needs are; fields.forEach(function(field){ bu[field] = gr.getValue(field) }) } return JSON.stringify([bu]); }, type: 'BillingInfoUtil' }); Dynamic content: Incidentdata <?xml version="1.0" encoding="utf-8" ?> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> <g:evaluate var="jvar_tasktypes" object="true" jelly="true"> // Changed to GlideRecord for demo purpose as I don't have the same tables or setup as you var objs = []; var gr= new GlideRecord('incident'); gr.groupBy('number'); gr.setLimit(5); gr.query(); while(gr.next()){ objs.push({'sys_id': gr.getValue('sys_id'),'number':gr.getDisplayValue('number')}); } objs; </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='select2-search form-control' onchange='filterTaskType()'> <option value="">--None--</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"></div> </div> </div> </div> </div> <script> function filterTaskType(){ var container = document.querySelector('.container'); var taskType = container.querySelector('#filter_task_type').value; var incDetails = container.querySelector('.list-group'); //Here is where the GlideAjax comes in instead of g:evaluate var ga = new GlideAjax('BillingInfoUtil'); ga.addParam('sysparm_name', 'getBillingInfo'); ga.addParam('sysparm_task_type', taskType); ga.getXML(callback); function callback(response) { var result = response.responseXML.documentElement.getAttribute("answer"); var details = JSON.parse(result); var keys = Object.keys(details[0]); var html = []; keys.forEach(function(key){ var label = key.toUpperCase().replace("_", " "); var text = details[0][key]; html.push('<div class="list-group-item"><h4 class="list-group-item-heading">'+ label + '</h4>'); html.push('<p class="list-group-item-text">' + text + '</p></div>'); }); incDetails.innerHTML = html.join(""); } } </script> </j:jelly>
How to dynamically show data of any table on dashboard using content block Jelly ServiceNow?
admin Changed status to publish December 19, 2023