Scripts of the 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, case 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 case comments.
If you use getNewsFromTicketEntries, you need to define the following in the news script:
- Queues which contain the news cases
- Scopes which the cases have to be in
- Classes of text which the comments have to be marked with
From each case, 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 case comments are:
- subject: the name and subject of the case which the comment belongs to
- author: the user or contact who added the comment
- content: the latest comment of the case 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 s script:
- Write a script of the type News publisher on the Scripts page.
- Assign the script in the news configuration:
- Web Client: Assign the script to the news widget in the page customization (see News widgets).
- CM/Track: Reference the script in the portal configuration (see Widgets 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 7: Pseudocode to create news items from an RSS channel
Coding example 2: Retrieving news from case comments
The following example shows a script of the type News publisher used to retrieve news from case comments:
Set queues = ["ServiceDesk"]
Set scopes = ["defaultScope/Service_Desk/Work_in_progress"]
Set textClasses = ["Solution"]
return newsService.getNewsFromTicketEntries(queues, scopes, textClasses)
Code example 8: Script to retrieve news from case 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.