Monday, January 05, 2009

ITSM Tip for the week: Adding a count to the Journal Tab

I’ve had a whole host of customers ask for this so I thought I'd add the details up. The script below counts the number of Journals that are related to the incident. 

How I’ve been using this script is to display the journal tab as “Journals (1)” (like the tabs in a HEAT system does). To do this you will need to add a field to the Incident that stores the Journal count (which I usually call JournalCount). Assign the script to the Field as a Calculation. Finally change the label of the tab to be a Named Expression. That Named expression should be of the Simple Calulation Type and would look something like this -> 'Journals ('+TRIM('{$[FIELD]Incident.JournalCount$}')+')'. 

The same principle will also apply for any other tab.

Journal Count Script 

import System

import Fusion

import Fusion.Api

 

class FusionScriptWrapper implements IScriptWrapper

{

     function FusionScriptWrapper()

     {

           // place constructor logic here

     }

 

     function Process(currentBusinessObject : Fusion.Api.BusinessObject, currentField : Fusion.Api.Field) : Object

     {

           var objReturn : Object

           var numberofjournals : int

          

           // Initialisation

           objReturn = true

          

           // Get all the Journals

           var bizCollectionJournals : Fusion.Api.BusinessObjectCollection

           bizCollectionJournals = currentBusinessObject.GetRelationship("IncidentContainsJournal").BusinessObjects

          

           // Check for Journals from the Relationship

           if(bizCollectionJournals != null)

           {

                     // Count the number of Journals

                     numberofjournals = bizCollectionJournals.Count

                     objReturn = numberofjournals

               

           }

 

          // Return the number of Journals

          return objReturn

     }

}

No comments: