Display approver details in a widget from sysapproval_approver table

Vikram3
Giga Guru

Hello,

Currently when I am selecting requests it shows all the details are visible in the widget (Request field). Similarly I need approver details widget for the RITM/REQ. Can you please help me out.

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

Create widget with below

HTML

<div ng-if="c.data.table == 'sc_req_item'" class="panel b" >
  <div class="panel-heading bg-primary">Approvals</div>
  <div class="panel-body">
   

    <table class="table table-striped table-responsive" ng-if="data.approvals.length">
      <thead>
        <tr>
          <th ng-repeat="field in data.fields_array track by $index">
            <div class="th-title">{{field.label}}</div>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="item in data.approvals track by item.sys_id">
          <td class="pointer" ng-repeat="field in data.fields_array" data-field="{{field}}" data-th="{{field.label}}">{{item[field.name]}}</td>
        </tr>
      </tbody>
    </table>

  </div>
</div>

 

Server Script

(function() {
	
	// Get table & sys_id
	data.sys_id = $sp.getParameter("sys_id");
  data.table = $sp.getParameter("table");
	
	var approvals = [];
	var gr = new GlideRecord("sysapproval_approver");
	gr.addQuery("sysapproval", data.sys_id);
	gr.addQuery('state','!=', 'not_required')
	gr.query();
	while (gr.next()) {
		var entry = {};
		entry.approver = gr.getDisplayValue('approver');
		entry.state = gr.getDisplayValue('state');
		entry.sys_id = gr.getValue('sys_id');
		approvals.push(entry);
	}

	data.approvals = approvals;
	data.fields_array = [
		{
			"name":"approver",
			"label":"Approver"
		},
		{
			"name":"state",
			"label":"State"
		}
		
	];

})();

View solution in original post

5 REPLIES 5

Mike Patel
Tera Sage

Create widget with below

HTML

<div ng-if="c.data.table == 'sc_req_item'" class="panel b" >
  <div class="panel-heading bg-primary">Approvals</div>
  <div class="panel-body">
   

    <table class="table table-striped table-responsive" ng-if="data.approvals.length">
      <thead>
        <tr>
          <th ng-repeat="field in data.fields_array track by $index">
            <div class="th-title">{{field.label}}</div>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="item in data.approvals track by item.sys_id">
          <td class="pointer" ng-repeat="field in data.fields_array" data-field="{{field}}" data-th="{{field.label}}">{{item[field.name]}}</td>
        </tr>
      </tbody>
    </table>

  </div>
</div>

 

Server Script

(function() {
	
	// Get table & sys_id
	data.sys_id = $sp.getParameter("sys_id");
  data.table = $sp.getParameter("table");
	
	var approvals = [];
	var gr = new GlideRecord("sysapproval_approver");
	gr.addQuery("sysapproval", data.sys_id);
	gr.addQuery('state','!=', 'not_required')
	gr.query();
	while (gr.next()) {
		var entry = {};
		entry.approver = gr.getDisplayValue('approver');
		entry.state = gr.getDisplayValue('state');
		entry.sys_id = gr.getValue('sys_id');
		approvals.push(entry);
	}

	data.approvals = approvals;
	data.fields_array = [
		{
			"name":"approver",
			"label":"Approver"
		},
		{
			"name":"state",
			"label":"State"
		}
		
	];

})();

Hi Mike, Thanks for the response. I created a widget and placed in 'Ticket Form' page. But nothing showed up. Does it requires any client controller?

Vikram3
Giga Guru

It worked. I have done changes in the widget attached.

Great!. Mine code works without making any changes. Any how please mark answer correct so it gets removed from unanswered list.