How to automatically set the colour/color for an incident without using Response Levels

Version 5

    Verified Product Versions

    LANDESK Service Desk 7.8.xLANDESK Service Desk 2016.xLANDESK Asset Central 2016.x

    Introduction

     

    The Process object in Service Desk has an attribute called Colour which is then inherited by the Incident, Problem, Change, Task, etc. objects.  The attribute is used as the background colour to the text at the top of the collection tree when viewing an incident, and as the background colour to query results (if the query is configured as such).  The primary way to set the value is using Response Level escalation actions, ie. at 75% of a response level change the colour to yellow, at 100% change it to red.  These can be configured through the Administration component of Console

     

    Setting the value away from Response Levels

     

    If you have the need to set the colour for an incident at a certain point in the process, or based on some logic that can't be implemented with response levels you can also set the value in other ways.  This document will explain how to know what value to set, a separate document describes how to set the value by either creating a calculation on the attribute or use automatic process actions: How to automatically set or update values on an incident

     

    How is the colour value stored?

     

    If you add the Colour attribute to your incident window design you'll see the value is actually displayed as a number.  This is a signed integer representation of an ARGB code.  This is something foreign to most; in computing and web design we normally think of colours in their red, green and blue (RGB) components either as decimals from 0 to 255 or hex values from 00 to FF.  For example 255,255,255 is the highest value for all three colours and shows as white.  ARGB includes the extra attribute of Alpha.  This is used to set the transparency of a colour although in Service Desk we generally just want this to be 255.  Here are some common colours and their ARGB integer values you can use when setting the Colour attribute in Service Desk:

     

    Transparent (the default colour for all new records): 16777215

    Black (0,0,0): 16777216

    White (255, 255, 255): -1

    Red (255, 0, 0): -65536

    Green (0, 255, 0): -16711936

    Blue (0, 0, 255): -16776961

     

    How to calculate any colour

     

    The easiest way to set the Colour attribute and not have to worry about converting the RGB values to an ARGB integer is using a calculation.  Following the two methods of setting the Colour from the document linked above you'll either be using a calculation anyway or using an automatic action and can right-click the Colour field and select Calculation (when using an automatic action you cannot specify an explicit value as Colour is a system attribute, you must use either a runtime value or calculation).

     

    Here is the formula you need to set the Colour from a set of RGB decimal values:

     

    import System
    import System.Drawing
    static def GetAttributeValue(Process):
     Red = 255
     Green = 0
     Blue = 0
     Alpha = 255
     Value = Color.FromArgb(Alpha, Red, Green, Blue)
     return Value.ToArgb()
    

     

    Notice the 2nd line - import System.Drawing.  This is required to get access to the Color class used further down the formula.  The example above will set the colour to red.  Edit the Red, Green and Blue variables to suit, or if you want to set the colour back to the transparent default set all three to 255 and change the Alpha variable to 0.  Otherwise the Alpha should always be kept at 255.