Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.
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.
Following assumptions are made to explain this use case:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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()); } } }
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()); } }
}