Harneet Sital
Mega Sage
Mega Sage

Recently I encountered a requirement where the client wanted to automatically create announcements from outage and knowledge articles. I created this as a helpful script that can help anyone. This can be added to a business rule with the conditions on when the announcement needs to be created including the start date, end date, and text that appears. 

 

Note: This is to create an announcement for portals

 

 

//Example code for creating an announcement from a KB article with specific type such as News

(function executeRule(current, previous /null when async/) {

        // Create an Announcement Record and various variables
	var announcementGR = new GlideRecord('announcement');
	announcementGR.initialize();	
	announcementGR.name = 'Autocreated from ' + current.number;
	announcementGR.title = current.short_description;	
	var fromDateTime = new GlideDateTime(); // adjust date according to your needs
	announcementGR.from = fromDateTime;	
	announcementGR.summary = current.text ;	
	announcementGR.type = "67eaf134e7a3320075c2a117c2f6a9d2,52fa79f8e763320075c2a117c2f6a991"; //Comma separated sys id for widget and banner type on the service portal
	announcementGR.click_target='urlNew';
	announcementGR.details_url='/sp?id=kb_article&sys_id='+current.sys_id;
	announcementGR.details_link_text = 'View Article';
	announcementGR.insert();	

	//Link Announcement to the specific portal
	var linkAnntoPortal = new GlideRecord('m2m_announcement_portal');
	linkAnntoPortal.initialize();
	linkAnntoPortal.announcement = announcementGR.sys_id;
	linkAnntoPortal.sp_portal = '81b75d3147032100ba13a5554ee4902b'; //sys id of the portal
	linkAnntoPortal.insert();

})(current, previous);

 

 

1 Comment