Using Case Field Values to Assign Tasks to Respective Teams

Let us consider the scenario where you want to assign tasks to a specific team based on the field value of a case record. For example, a user want to assign a task to Team A based on the value for a field called Zone. This article helps you achieve that objective.

Assumptions

      Following assumptions are made to explain this use case:

  • The case object has a field Zone that contains the zone information.
  • The user has created teams based on the Zone values.

Basic Flow

  1. When the end user creates a case, the zone details are captured as part of the record.
  2. A task is created for the associated case.
  3. Invoke the attached class from "Business rules update event rules".
  4. Whenever we update the task, if the value of the Zone field for the case and the team name matches, the task is assigned to the respective team and the task zone is also updated by the system.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


package com.platform.experian.zone;

import com.platform.api.*;

public class UpdateZone
{
    public void updateFindingZoneInTask(Parameters params)throws Exception
    {
      try
      {
      String taskId = params.get("id");
      String caseInfo = params.get("related_to");
      String caseId = caseInfo.split(":")[1];
        
        //Setup query to get finding details      
        String caseQuery="SELECT id,cases_zone FROM cases where id = "+caseId;
        Result queryResult = Functions.execSQL(caseQuery);
        Parameters updatedParams = Functions.getParametersInstance();
        if (queryResult.getCode() == 1) {
          ParametersIterator iterator = queryResult.getIterator();
          while(iterator.hasNext())
          {
            Parameters caseParams = iterator.next();
            
            // this flag will help to do not execute recursive update.
            updatedParams.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_RULES,"1");
            
            // get the fields from finding record update in the task.
            String zone= caseParams.get("cases_zone");
            updatedParams.add("task_zone", zone);
            if(zone != null && !"".equals(zone)){
              Functions.debug(zone);
               
              //Setup query to get the team id based on finding zone
              String query="SELECT last_name, user_type, id FROM USER where last_name='"+zone+"' AND user_type='O'";
              Result teamResult = Functions.execSQL(query);
              if(teamResult.getCode() == 1){
                ParametersIterator teamIterator = teamResult.getIterator();
                while(teamIterator.hasNext())
              {
                Parameters teamParams = teamIterator.next();
                String teamId=teamParams.get("id");
                updatedParams.add("owner_id",teamId);
              }
             }
            }
            
          }
          
        }
        Result result = Functions.updateRecord("tasks", taskId, updatedParams);
        if(result.getCode() == 0)
        {
          Logger.info("Finding fields updated successfully in the TASK \n"
                      + result.getMessage(), "Update");
        }
        else
        {
          String msg = "Error in updating finding fields.";
          Logger.info(msg + ":\n" + result.getMessage(), "Update");
          Functions.throwError(msg + ".");
        }
      }
      
      
      catch(Exception e)
      {
        Functions.debug("Exception:"+e.getMessage());
            Functions.throwError(e.getMessage());
      }
      
    }

}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------