Scripts of Type News Publisher
Scripts of the type News publisher are used to determine which news are displayed on the Web Client dashboard and/or on the welcome page of CM/Track. The news which are returned by the script can be retrieved from several sources, for example, ticket comments or RSS feeds, or created directly within the script.
The news script returns a list of news items to be displayed in the Web Client or CM/Track. There are two ways of creating this list:
- Create a list of objects of the class NewsItem.
- Use the convenience method getNewsFromTicketEntries of the class NewsService to retrieve news directly from ticket comments.
If you use getNewsFromTicketEntries, you need to define the following in the news script:
- Queues which contain the news tickets
- Scopes which the tickets have to be in
- Classes of text which the comments have to be marked with
From each ticket, the latest comment marked with one of the text classes is displayed in the news. Only history entries of the type comment can be used in news scripts. If any other entry, for example an email, is marked with the configured text class, the entry is ignored.
The default values for news items from ticket comments are:
- subject: the name and subject of the ticket which the comment belongs to
- author: the engineer or customer who added the comment
- content: the latest comment of the ticket which has the specified text class, including inline images and formatting
- creation date: the date when the comment was added
- update date: the date when the comment was updated
- color: the background color of the text class
Steps to use a news script:
- Write a script of the type News publisher in the Scripts section of the Admin Tool.
- Assign the script in the news configuration:
- Web Client: Assign the script to the news widget in the page customization (see Attributes for News Widgets).
- CM/Track: Reference the script in the client configuration of the welcome page (see Displaying News on the Welcome Page)
- Adapt the default values for displaying news in the news configuration (optional).
Coding Example 1: Pseudocode to Retrieve News
The following pseudocode example shows how to build a list of NewsItems from an RSS channel.
def newsList = []
def url = "myurl"
Locale.setDefault(Locale.US)
try{
def rss = new XmlSlurper().parseText(url)
rss.channel.item.each {
def date = new Date().parse("EEE, dd MMM yy HH:mm:ss", "${it.pubDate}".substring(0, 23))
newsList.add(new NewsItem("${it.title}" as String, null, "${it.description}", date, null, null))
}
}catch(Exception e){
newsList.add(new NewsItem("No response from server" as String, ""))
}
return newsList
Code example 76: Pseudocode to create news items from an RSS channel
Coding Example 2: Retrieving News from Ticket Comments
The following example shows a script of the type News publisher used to retrieve news from ticket comments:
Set queues = ["ServiceDesk"]
Set scopes = ["defaultScope/Service_Desk/Work_in_progress"]
Set textClasses = ["Solution"]
return newsService.getNewsFromTicketEntries(queues, scopes, textClasses)
Code example 77: Script to retrieve news from ticket entries
The script retrieves the entries as objects of the class TicketEntryNewsItem. It is possible to extract data from the retrieved entries and modify them as desired.