How to Retrieve SysID in Service Portal Announcement Widget?

Tarosan
Tera Contributor

 

Hello,

I am currently working on customizing an Announcement Widget in the Service Portal, and I need to display attachments along with titles for each announcement. To access the attachments, it seems necessary to retrieve the SysID for each announcement, but I am encountering difficulties as the SysID is not included in the data provided by the default service or method I am using.

I checked the server script and client controller, but it seems the SysID is not being fetched or passed to the frontend.

・Server script

(function() {
    if (options.title)
        options.title = gs.getMessage('{0}', options.title);
    else
        options.title = gs.getMessage('Announcements');
	options.max_records = options.max_records ? options.max_records : 20;
	options.paginate = options.paginate === 'true' && options.max_records;
	options.use_display_style = options.use_display_style === 'true';
	data.rowsMessage = gs.getMessage('Rows {0} - {1} of {2}');

	if (options.view_all_page) {
		var gr = new GlideRecord('sp_page');
		gr.get(options.view_all_page);
		options.view_all_page = gr.getValue('id');
	}

	if (options.type) {
		var types = [];

		options.type.split(',').forEach(function(type) {
			var gr = new GlideRecord('announcement_consumer_type');
			gr.get(type);
			types.push(gr.getDisplayValue('name'));
		});

		options.type = types.join(',');
	}
})();

・Client controller

function($scope, $timeout, $location, spAnnouncement, spUtil, spAriaUtil) {
  var c = this;

	c.wid = 'spw-announcements-' + new Date().getTime();
	c.accessibilityOff = spAriaUtil.g_accessibility === 'false';
	c.announcements = [];
	c.totalAnnouncements = 0;

	c.toggleDetails = function(announcement) {
		announcement.expanded = !announcement.expanded;
	};

	c.isViewAllPage = function() {
		return $location.search().id === c.options.view_all_page;
	};

	c.getNumArray = function(number) {
		return new Array(number);
	};

	c.getPageInfo = function() {
		var limit = parseInt(c.options.max_records, 10);
		var offset = (c.currentPage - 1) * limit;
		var end = offset + limit;

		return spUtil.format(c.data.rowsMessage, {
			'0': offset + 1,
			'1': end < c.totalRecords ? end : c.totalRecords,
			'2': c.totalRecords
		});
	};

	c.goToPage = function(page, firstLoad) {
		var result = spAnnouncement.get(spAnnouncement.filterOnType(c.options.type), c.options.max_records, page);

		c.currentPage = page;
		c.totalPages = result.totalPages;
		c.totalRecords = result.totalRecords;

		c.announcements = result.data;
		c.totalAnnouncements = result.data.length;
		
		c.announcements.forEach(function(a) {
			a.canExpand = a.summary || a.targetLinkText;
			a.expanded = false;
		});

		$(document).ready(function() {
			if (!firstLoad)
				setFocus();
		});
	};

	c.linkSetup = function(a) {
    a.linkTarget = '_self';

    if ('urlNew' === a.clickTarget) {
      a.linkTarget = '_blank';
    }

    a.linkType = !a.targetLink ? 'none' : a.targetLinkText ? 'normal' : 'title';
  };
	
	c.getDisplayStyle = function(announcement) {
		return announcement.displayStyle || {
			backgroundColor: '#006ed5',
			foregroundColor: '#ffffff',
			alignment: 'LEFT'
		};
	};

	function setFocus() {
		var ul = $('.' + c.wid).find('ul');

		if (!ul.length) {
			$timeout(setFocus);
			return;
		}

		$timeout(function() {
			ul.first().focus();
		}, 20);
	}

	c.goToPage(1, true);
}

Could anyone please guide me on how to modify the widget or recommend a method to successfully retrieve and display the SysID, and consequently the attachments, in the Service Portal Announcement Widget? Any specific examples or tips would be greatly appreciated.

Thank you in advance for your help!

0 REPLIES 0