News scripts
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 classNewsService
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
- Enum value which needs to be set for a defined data field (optional)
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 TODO News widgets).
- CM/Track: Reference the script in the portal configuration (see TODO Widgets on the welcome page)
- Adapt the default values for displaying news in the news configuration (optional).
Coding examples
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
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 = ["Frequently_Asked_Questions"]
Set scopes = ["defaultScope/faq/published", "defaultScope/faq/new"]
Set textClasses =["Solution"]
enumValue = enumService.getValueByName("countryEnumGroup", "germany")
Set<AbstractField> newsFields = Collections.singleton(new EnumField(new FieldKey("helpdesk_standard", "country"), enumValue))
return newsService.getNewsFromTicketEntries(queues, scopes, textClasses, newsFields)
Das Skript ruft die Einträge als Objekte der Klasse TicketEntryNewsItem
ab. Die Daten können aus den abgerufenen Einträgen extrahiert und nach Bedarf aktualisiert werden.