Share This:

Some Background Info:

 

There is an idea submitted for this feature https://communities.bmc.com/ideas/3039, so this blog post is about how to implement a workaround until such feature is provided out of the box.

 

As of this writing, there is no out of the box way to default an incident's impact or urgency through administration except through templates. However, it may be unfeasible to require help desk analysts to pick a template when logging every incident, so as a Remedyforce Administrator you're looking for other options to ensure (1) meaningful defaults are assigned to fields and (2) reduce number of fields users have to manually enter.

 

Many folks in the BMC Community have offered workarounds from special templates to workflows and apex triggers. Inspired by Paul Donders trigger solution, below are instructions on how to create and configure the necessary workflows and triggers.

 

Please note, the setup steps below must be performed first in your sandbox then deployed to your production instance because apex code is involved (and that's best practice!)

 

What we'll be doing in this setup:

 

  1. Create two (2) custom fields on Incident object for specifying default values for impact and urgency
  2. Create two (2) workflow rules on Incident object to signal that our code should run
  3. Create two (2) workflow field updates on Incident object to set values into the custom fields from step 1
  4. Create one (1) apex class to contain code and logic for assigning default values to incident impact and urgency
  5. Create one (1) apex trigger on Incident object to invoke the apex class from step 4
  6. Create one (1) apex test class to validate our code and meet Salesforce code coverage requirements to deploy to production

 

 

Step 1 - Create Custom Fields

 

Change Impact Controller custom Incident field
change_impact_controller_incident_field.png

Field Label = Change Impact Controller

Field Name = Change_Impact_Controller

Description = This field is used to activate the workflow / trigger for defaulting the Impact look up field to this value. This workaround is needed because as a managed package, Impact cannot be changed to have a default, and as a look up field, it is not available to Workflow Field Updates.

Help Text = This field is used to activate the workflow / trigger for defaulting the Impact look up field to this value.

Length = 80

 

 

Change Urgency Controller custom Incident field

change_urgency_controller_incident_field.png

Field Label = Change Urgency Controller

Field Name = Change_Urgency_Controller

Description = This field is used to activate the workflow / trigger for defaulting the Urgency look up field to this value. This workaround is needed because as a managed package, Urgency cannot be changed to have a default, and as a look up field, it is not available to Workflow Field Updates.

Help Text = This field is used to activate the workflow / trigger for defaulting the Urgency look up field to this value.

Length = 80

 

 

Step 2 - Create Workflow Rules

 

Set Incident Impact Workflow Rule
set_incident_impact_workflow.png

Object = Incident

Rule Name = Set Incident Impact

Description = Workflow to default Impact when it is not set on the incident. This is to ensure the field has a value and automate its assignment.

Evaluation Criteria = Evaluate the rule when a record is created, and every time it's edited

Rule Criteria = Run this rule if the following formula evaluates to true

                    ISBLANK( BMCServiceDesk__FKImpact__c )

 

 

Set Incident Urgency Workflow Rule
set_incident_urgency_workflow.png

Object = Incident

Rule Name = Set Incident Urgency

Description = Workflow to default Urgency when it is not set on the incident. This is to ensure the field has a value and automate its assignment.

Evaluation Criteria = Evaluate the rule when a record is created, and every time it's edited

Rule Criteria = Run this rule if the following formula evaluates to true

                    ISBLANK( BMCServiceDesk__FKUrgency__c )

 

 

Step 3 - Create Field Updates

 

Set Change Impact Controller Field Update
set_change_impact_controller_field_update.png

Name = Set Change Impact Controller

Unique Name = Set_Change_Impact_Controller

Description = Set the value of this field to what the incident's impact should be set to. Trigger will analyze this field to perform update if this field is not blank. Trigger blanks this field once done so that the workflow rule has to fire to trip the trigger again.

Object = Incident

Field to Update = Incident: Change Impact Controller

New Value = use a formula to set the new value

                    "MEDIUM" (or the name of any Impact in your system you want to use for default)

Re-evaluate Workflow Rules after Field Change = yes, checked (so Priority will be re-calculated by Remedyforce)

Set Change Urgency Controller Field Update
set_change_urgency_controller_field_update.png

Name = Set Change Urgency Controller

Unique Name = Set_Change_Urgency_Controller

Description = Set the value of this field to what the incident's urgency should be set to. Trigger will analyze this field to perform update if this field is not blank. Trigger blanks this field once done so that the workflow rule has to fire to trip the trigger again.

Object = Incident

Field to Update = Incident: Change Urgency Controller

New Value = use a formula to set the new value

                    "MEDIUM" (or the name of any Urgency in your system you want to use for default)

Re-evaluate Workflow Rules after Field Change = yes, checked (so Priority will be re-calculated by Remedyforce)

 

 

Step 4 - Create Apex Class

 

Code is shown below for quick reference, it is also provided as a text file attachment at bottom of this blog post.

 

/**
 * Written by Doug Ayers, https://communities.bmc.com/people/douglas.ayers%40fotlinc.com
 * Inspired by Paul Donders, https://communities.bmc.com/people/p.donders@infravision.com//communities.bmc.com/people/p.donders@infravision.com
 * BMC Communities, https://communities.bmc.com/ideas/3039
*/
public class BMCRF_IncidentTriggerHelper
{
    public static void checkAndSetImpact( List<BMCServiceDesk__Incident__c> incidents ) {


     // get list of all active impacts
        List<BMCServiceDesk__Impact__c> impactList = new List<BMCServiceDesk__Impact__c>([
            SELECT id, name FROM BMCServiceDesk__Impact__c WHERE BMCServiceDesk__inactive__c = false
        ]);


        // convert list of impacts into a map so we can do look ups by impact name (eg, 'MEDIUM')
        Map<String, BMCServiceDesk__Impact__c> impactMap = new Map<String, BMCServiceDesk__Impact__c>();
        for ( BMCServiceDesk__Impact__c impact : impactList ) {
            impactMap.put( impact.name, impact );
        }


        // loop through each incident and check if its impact should be set
        for ( BMCServiceDesk__Incident__c incident : incidents ) {


            System.debug( 'Incident Impact: ' + incident.BMCServiceDesk__FKImpact__r );
            System.debug( 'Change Impact Controller: ' + incident.Change_Impact_Controller__c );


            if ( String.isNotBlank( incident.Change_Impact_Controller__c ) ) {


             // get the impact reference from the map whose name matched the custom controller field's value
                BMCServiceDesk__Impact__c impact = impactMap.get( incident.Change_Impact_Controller__c );


                if ( impact != null ) {


                    System.debug( 'Changing impact to: ' + impact );


                    incident.BMCServiceDesk__FKImpact__c = impact.id;


                } else {


                    System.debug( LoggingLevel.WARN, 'Unknown impact to set: ' + incident.Change_Impact_Controller__c );


                }


                // clear the controller value so this code doesn't run again
                // unless the workflow rules reset the controller value
                incident.Change_Impact_Controller__c = null;


            }


        }


    }


    public static void checkAndSetUrgency( List<BMCServiceDesk__Incident__c> incidents ) {


     // get list of all active urgencies
        List<BMCServiceDesk__Urgency__c> urgencyList = new List<BMCServiceDesk__Urgency__c>([
            SELECT id, name FROM BMCServiceDesk__Urgency__c WHERE BMCServiceDesk__inactive__c = false
        ]);


        // convert list of urgencies into a map so we can do look ups by urgency name (eg, 'MEDIUM')
        Map<String, BMCServiceDesk__Urgency__c> urgencyMap = new Map<String, BMCServiceDesk__Urgency__c>();
        for ( BMCServiceDesk__Urgency__c urgency : urgencyList ) {
            urgencyMap.put( urgency.name, urgency );
        }


        // loop through each incident and check if its urgency should be set
        for ( BMCServiceDesk__Incident__c incident : incidents ) {


            System.debug( 'Incident Urgency: ' + incident.BMCServiceDesk__FKUrgency__r );
            System.debug( 'Change Urgency Controller: ' + incident.Change_Urgency_Controller__c );


            if ( String.isNotBlank( incident.Change_Urgency_Controller__c ) ) {


  // get the urgency reference from the map whose name matched the custom controller field's value
                BMCServiceDesk__Urgency__c urgency = urgencyMap.get( incident.Change_Urgency_Controller__c );


                if ( urgency != null ) {


                    System.debug( 'Changing urgency to: ' + urgency );


                    incident.BMCServiceDesk__FKUrgency__c = urgency.id;


                } else {


                    System.debug( LoggingLevel.WARN, 'Unknown urgency to set: ' + incident.Change_Urgency_Controller__c );


                }


                // clear the controller value so this code doesn't run again
                // unless the workflow rules reset the controller value
                incident.Change_Urgency_Controller__c = null;


            }


        }


    }
}



 

 

Step 5 - Create Trigger

 

Code is shown below for quick reference, it is also provided as a text file attachment at bottom of this blog post.

 

/**
 * Written by Doug Ayers, https://communities.bmc.com/people/douglas.ayers%40fotlinc.com
 * Inspired by Paul Donders, https://communities.bmc.com/people/p.donders@infravision.com//communities.bmc.com/people/p.donders@infravision.com
 * BMC Communities, https://communities.bmc.com/ideas/3039
*/
trigger BMCRF_IncidentTrigger on BMCServiceDesk__Incident__c ( before update ) {


    if ( Trigger.isBefore && Trigger.isUpdate ) {
        BMCRF_IncidentTriggerHelper.checkAndSetImpact( Trigger.new );
        BMCRF_IncidentTriggerHelper.checkAndSetUrgency( Trigger.new );
    }


}



 

Step 6 - Create Apex Test

 

Code is shown below for quick reference, it is also provided as a text file attachment at bottom of this blog post.

 

@isTest
private class BMCRF_IncidentTriggerHelperTest
{
    @isTest
    static void test_set_incident_impact_and_urgency() {


        BMCServiceDesk__Impact__c impact = new BMCServiceDesk__Impact__c();
        impact.name = 'MEDIUM';


        insert impact;


        BMCServiceDesk__Urgency__c urgency = new BMCServiceDesk__Urgency__c();
        urgency.name = 'MEDIUM';


        insert urgency;


        BMCServiceDesk__Category__c category = new BMCServiceDesk__Category__c();
        category.name = 'Test Category';
        category.BMCServiceDesk__AvailableForIncidents__c = true;


        insert category;


        BMCServiceDesk__Incident__c incident = new BMCServiceDesk__Incident__c();
        incident.BMCServiceDesk__incidentDescription__c = 'Test';
        incident.BMCServiceDesk__IncidentType__c = 'Incident';
        incident.BMCServiceDesk__FKCategory__c = category.id;
        incident.BMCServiceDesk__FKClient__c = UserInfo.getUserId();


        System.assert( incident.BMCServiceDesk__FKImpact__c == null );
        System.assert( incident.BMCServiceDesk__FKUrgency__c == null );


        Test.startTest();


        insert incident;


        Test.stopTest();


        incident = [ select id, BMCServiceDesk__Impact_Id__c, BMCServiceDesk__Urgency_Id__c from BMCServiceDesk__Incident__c where id = :incident.id ];


        System.assert( incident.BMCServiceDesk__Impact_Id__c == 'MEDIUM' );
        System.assert( incident.BMCServiceDesk__Urgency_Id__c == 'MEDIUM' );


    }


}