Service portal approval menu

akin9
Tera Contributor

Hello experts,

 

We want to show approvals history on approvals menu on service portal.

I have tried with URL from the sysapproval table its redirects to UI approval table

but client want to show history.

akin9_0-1708451839122.png

 

Kindly support to achieve this!

 

3 REPLIES 3

Sumanth16
Kilo Patron

Hi @akin9 ,

 

Please refer to below thread:

https://www.servicenow.com/community/now-platform-forum/how-to-show-approval-history-of-ritm-on-serv...

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,
Suamnth Meda

akin9
Tera Contributor

Hi @Sumanth16 

 

Thanks for the quick reply we want to show on the all approvals history on menus.

but unfortunately, above not works for me.

akin9
Tera Contributor

Hi @Sumanth16 /team

We have a incident menu its working fine based on the below URL

Type - URL

URL - ?id=requests&table=incident

akin9_0-1708455902856.png

 

 

Same tried for approval table format is coming like incident but data is not getting populated.

but we need to do changes on below scripts can you pls help on this.

URL - ?id=requests&table=sysapproval_approver

 

<div class="panel panel-default b" ng-init="c.trackPage()">
 <div class="panel-heading" ng-show="::!data.is_associated_ticket_tab">
    <h2 class="panel-title">{{::data.messages.myRequestsTitle}}</h2>
  </div> 	
  <div class="panels-container list-group">
			<div ng-show="::!data.is_associated_ticket_tab" class="list-group-item row requests-header-container">
          <div class="col-md-3 col-xs-12 m-b-sm fit-content">
            <div class="form-inline control-view" ng-if="c.options.show_view == 'true'">
            	<label class="control-label hidden-xs wrapper-xs " id="label_view" for="view">${View}</label>
              <select ng-model="c.viewFilter" id="view" class="sc-basic-select adjust-width" ng-change="c.changeView()" style="width:80%">
                <option value="open" selected="true">{{::data.messages.openRequests}}</option>
                <option value="close">{{::data.messages.closedRequests}}</option>
              </select>
            </div>
          </div>
          <div class="col-md-4 col-xs-12 padding-left-large fit-content">
            <div class="input-group" style="width:100%">
              <input ng-model="c.filterText" ng-keypress="c.checkEnter($event)"class="form-control" style="width:100%" placeholder="{{data.filterMsg}}" aria-label="{{data.filterMsg}}">
              <span class="input-group-btn">
                <button class="btn btn-default align-icon" type="button" ng-click="c.search()" title="{{data.filterMsg}}" aria-label="{{data.filterMsg}}">
                	<i class="fa fa-search"></i>
                </button>
              </span>
            </div><!-- /input-group -->
              
          </div>
    	</div>
    	<div ng-if="c.data.request.req_list.length == 0 && !c.filterText" class="panel-body panels-container">
        ${You do not have any requests} 
      </div>
    	<div ng-if="c.data.request.req_list.length == 0 && c.filterText" class="panel-body panels-container">
        ${Search didn't match any requests} 
      </div>
    <div role="table" ng-if="c.data.request.req_list.length > 0" class="table" aria-label="{{::data.messages.myRequestsTitle}}">
      <div ng-show="::!data.is_associated_ticket_tab" role="rowgroup" class="column-headers">
        <div role="row" class="list-group-item table-responsive">
          <span role="columnheader" class="col-xs-6 padder-r-none padder-l-none">{{::data.tableName}}</span>
          <span role="columnheader" class="col-xs-3 padder-r-none padder-l-none">${State}</span>
          <span role="columnheader" class="col-xs-3 padder-r-none padder-l-none">${updated_capital}</span>
        </div>
   	  </div>
      <ul role="rowgroup" class="padder-l-none padder-r-none">
        <li role="row" class="list-group-item table-responsive" ng-repeat="item in c.data.request.req_list | limitTo: c.data.lastLimit track by item.sys_id" style="margin:0px" >
          <div role="cell" class="col-xs-6 padder-l-none padder-r-none main-column">
            <div class="primary-display">
              <a href="?id={{::item.url.id}}&table={{::item.url.table}}&sys_id={{::item.url.sys_id}}" sn-focus="{{::item.highlight}}" aria-label="{{::item.display_field}} , {{::item.display_number}}"> {{::item.display_field}} </a>
            </div>
            <small class="text-muted">
              <div ng-repeat="f in item.secondary_displays" class="secondary-display">
                <span >{{::f.display_value}}</span>
              </div>
            </small>
          </div>
          <div role="cell" class="col-xs-3 padder-l-none padder-r-none state-column">
            <div class="state">
              <span> {{::item.state}}</span>
            </div>
          </div>
          <div role="cell" class="col-xs-3 padder-l-none padder-r-none updated-column">
            <div class="updated">
              <i class="fa fa-clock-o" aria-hidden="true" title="${Updated}"></i>
              <sn-time-ago timestamp="::item.updated_on"/>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</div>
<div class="col-sm-12 pull-none" ng-if="c.data.hasMore" style="padding-bottom:15px">
					<div class="text-a-c" ng-if="c.fetching">
          	<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i>
						<span class="sr-only">${Loading more requests}</span>  
  	      </div>
          <button class="btn btn-default btn-show-more" ng-click="c.loadMore()"> {{::data.messages.showMoreRequests}} </button>  
      </div>

 

Server

 

(function() {
	
	var localInput = input; //to safeguard pullution of "input" via BR or other scripts
	
	var alsoRequest = false;
	
	data.tableName = '';
	var msg = data.messages = {};
	msg.myRequestsTitle = options.title? gs.getMessage(options.title) : gs.getMessage('My Requests');
	msg.openRequests = gs.getMessage('Open requests');
	msg.closedRequests = gs.getMessage('Closed requests');
	msg.showMoreRequests = gs.getMessage('Show More Requests');
	data.filterMsg = gs.getMessage("Search open requests");

	var recordTable = options.record_table || $sp.getParameter("table");
	var recordId = options.record_id || $sp.getParameter("sys_id");
	
	data.is_associated_ticket_tab = options.is_associated_ticket_tab;
	
	if (localInput && localInput.view === 'open')
		data.filterMsg = gs.getMessage("Search open requests");
	else if (localInput && localInput.view === 'close')
		data.filterMsg = gs.getMessage("Search closed requests");
	
	data.is_new_order = (($sp.getParameter("is_new_order") + '') === "true");
	data.requestSubmitMsg = gs.getMessage('Thank You. Your request has been submitted');
	
	function getField(gr, name) {
			var f = {};
			var id = gr.getUniqueValue();
			gr = new GlideRecord(gr.getRecordClassName());
			gr.get(id);
			f.display_value = gr.getDisplayValue(name);
			f.value = gr.getValue(name);
			var ge = gr.getElement(name);
		  if (ge) {
				var ed = ge.getED();
				if (ed)
					f.type = ed.getInternalType();
				f.label = ge.getLabel();
			}
			return f;
	}

	function getMyRequestSysIds() {
		var ids = {};
		var rq_filter = new GlideRecord('request_filter');
		rq_filter.addActiveQuery();
		if (recordTable)
			rq_filter.addQuery('table', recordTable);
		if (rq_filter.isValidField('applies_to'))
			rq_filter.addQuery('applies_to', 1).addOrCondition('applies_to', 10);
		rq_filter.query();
		while(rq_filter.next()) {
			var tableName = rq_filter.table_name;
			if (rq_filter.isValidField('table'))
				tableName = rq_filter.table;
			var gr = new GlideRecord(tableName);
			gr.addQuery(rq_filter.filter);
			gr.query();
			if (tableName == 'sc_request')
				alsoRequest = true;
			while(gr.next()) {
				var portalSettings = {};
				portalSettings.page = rq_filter.portal_page.nil()? '' : rq_filter.portal_page.getDisplayValue() + '';
				portalSettings.primary_display = rq_filter.primary_display.nil()? '': rq_filter.primary_display + '';
				portalSettings.secondary_displays = rq_filter.secondary_display.nil()? '': rq_filter.secondary_display + '';
				ids[gr.sys_id + ''] = portalSettings;
			}
		}
		return ids;
	}
	
	// retrieve the request's
	var myRequestMap = getMyRequestSysIds();
	var taskIDs = Object.keys(myRequestMap);

	var gr = new GlideRecordSecure('task');
	
	if (!data.is_associated_ticket_tab) {
	if (localInput && localInput.view === 'open') 
		gr.addActiveQuery();
	else if (localInput && localInput.view === 'close')
		gr.addQuery('active', 0);
	else
		gr.addActiveQuery();
	} else {
			if (recordTable != 'universal_request') {
				//Check if universal_request field is present and it is a universal request
				var taskRecord = new GlideRecordSecure('task');
				taskRecord.get(recordId);
				if (taskRecord.isValid() && !taskRecord.universal_request.nil()) {
						var qc = gr.addQuery('parent',taskRecord.universal_request);
						qc.addOrCondition('parent','IN',new sn_uni_req.UniversalRequestUtilsSNC().getChildRequests(taskRecord.universal_request));						
				} 
				else
						gr.addQuery('parent',recordId);
			} 
			else {
				var qc = gr.addQuery('parent',recordId);
				qc.addOrCondition('parent','IN',new sn_uni_req.UniversalRequestUtilsSNC().getChildRequests(recordId));						
			}
	}

	gr.orderByDesc('sys_updated_on');
	if (localInput && localInput.search_text) {
			var req = [];
			var task = new GlideRecordSecure('task');
			task.addQuery('123TEXTQUERY321', localInput.search_text);
			if (localInput && localInput.view === 'open') 
				task.addQuery('active', 1);
			else if (localInput && localInput.view === 'close')
				task.addQuery('active', 0);
			else
				task.addQuery('active', 1);
			task.addQuery('sys_id', taskIDs);
			task.query();

			while(task.next())
				req.push(task.getUniqueValue());
		
			if (alsoRequest) {
				var ritmGR = new GlideRecord('sc_req_item');
				if (localInput && localInput.view === 'open') 
					ritmGR.addQuery('request.active', 1);
				else if (localInput && localInput.view === 'close')
					ritmGR.addQuery('request.active', 0);
				else
					ritmGR.addQuery('request.active', 1);
				ritmGR.addQuery('123TEXTQUERY321', localInput.search_text);
				ritmGR.addQuery('request.sys_id', taskIDs);
				ritmGR.query();
				while(ritmGR.next())
					req.push(ritmGR.getValue('request'));
			}
			gr.addQuery('sys_id', req);
		}
		else 
			gr.addQuery('sys_id', taskIDs);
	gr.query();

	data.request = {};

	data.request.req_list = [];
	var recordIdx = 0;	
	var limit = options.items_per_page? options.items_per_page : 15;
	if (localInput && localInput.action == 'fetch_more')
		data.lastLimit = localInput.lastLimit + limit;
	else
		data.lastLimit = limit;

	data.hasMore = false;
	while (recordIdx != data.lastLimit && gr.next()) {
		msg.myRequestsTitle = gs.getMessage("My "+gr.getClassDisplayValue());
		data.tableName = gr.getClassDisplayValue();
		msg.openRequests = gs.getMessage("Open "+gr.getClassDisplayValue());
		msg.closedRequests = gs.getMessage("Closed "+gr.getClassDisplayValue());
		msg.filterMsg = gs.getMessage("Search open "+gr.getClassDisplayValue());
		msg.showMoreRequests = gs.getMessage('Show More '+gr.getClassDisplayValue());
		var portalSettings = myRequestMap[gr.getUniqueValue()];
		if (typeof portalSettings == 'undefined')
			portalSettings = {};

		var record = {};
		record.sys_id = gr.getValue('sys_id');

		if (gr.getRecordClassName() == 'sc_request') {
				var ritm = new GlideRecord("sc_req_item");
				ritm.addQuery("request", gr.getUniqueValue());
				ritm.query();
				if (ritm.getRowCount() == 0)
					continue;
				if (ritm.getRowCount() > 1)
					record.display_field = gs.getMessage("{0} requested items", ritm.getRowCount());
				else {
					ritm.next();
					record.display_field = ritm.cat_item.getDisplayValue() || ritm.getDisplayValue("short_description");
				}
				record.url = { id: portalSettings.page? portalSettings.page: 'sc_request', table: 'sc_request', sys_id: record.sys_id};
		} else {
				record.display_field = portalSettings.primary_display ? getField(gr, portalSettings.primary_display).display_value : getField(gr, 'number').display_value;
				record.url = { id: portalSettings.page? portalSettings.page :'ticket', table: gr.getRecordClassName(), sys_id: record.sys_id};
		}
		record.display_number = getField(gr, 'number').display_value || '';
		if (portalSettings.secondary_displays) {
			record.secondary_displays = [];
			portalSettings.secondary_displays.split(",").forEach(function (sDisplay){
				record.secondary_displays.push(getField(gr, sDisplay));
			});
		}
		else 
			record.secondary_displays = getField(gr, 'short_description');
		
		record.updated_on = gr.getValue('sys_updated_on');
		record.state = gr.getDisplayValue('state');
		if((recordIdx !== 0) && (data.lastLimit - limit === recordIdx))
			record.highlight = true;

		data.request.req_list.push(record);
		recordIdx++;
	}

	if (gr.next())
			data.hasMore = true;
})();