Skip to main content
Mitratech Success Center

Client Support Center

Need help? Click a product group below to select your application and get access to knowledge articles, webinars, training content, and release notes or to contact our support team.

Authorized users - log in to create a ticket, view tickets status and check your success plan details.

 

Automated Actions

This section provides samples of automated actions written in Java in the following sections:

Rule Actions

You can use the following samples of automated actions written in Java with rules of type Custom Action:

For parameterized rule action samples, see Parameterized Actions. For wizard page action samples, see Wizard Page Actions.

Copying Values from Parent to Multiple Child Records 

The following Java action gets the values of two custom fields of type date in the current object record (custom object Complaint) and copies the values of these fields into date fields in the child records of a particular custom object definition (custom object Served Company).

Business Rule

When the Service Date and Received Date custom fields in the parent complaint record update, the same values must copy to the corresponding Service Date and Received Date fields in the child served company records.

Action

Copy the values from the date custom fields in the parent complaint record to the corresponding date custom fields in all of its child served company records.

Sample Values

Object Definition:

COMP (custom object Complaint)
SECO (custom object Served Company, child of Complaint)

Categories:

COMP (root category of Complaint)
SECO (root category of Served Company) 

Custom Fields:

In Complaint:

  • serviceDate (Date)
  • receivedDate (Date) In Served Company:
  • serviceDate (Date)
  • receivedDate (Date)

Java Action: Copying Values from Parent to Multiple Child Records 

public class CopyingValuesFromParentToMultipleChildRecords extends 
CustomAction<Project> {
    @Override
    public void action(final Project project) {
        // Run as system user to bypass security 
        platform.getUtilityService().runAsSystemUser(new Callable() {
            @Override
            public void call() { 
            // Get service date and received date field values from parent
            CalendarDate serviceDate = 
            project.getCalendarDateFieldValue("COMP", "serviceDate");
            CalendarDate receivedDate = 
            project.getCalendarDateFieldValue("COMP", "receivedDate");
            
            // Get a set of child objects for a specific child object definition
            List<Project> servedCompanies = 
            platform.getProjectService().getChildProjects(project, "SECO");
            
            for (Project company : servedCompanies) {
                // Set the values from the parent project fields onto each child
                company.setCalendarDateFieldValue("SECO", "serviceDate", serviceDate);
                company.setCalendarDateFieldValue("SECO", "receivedDate", receivedDate);
            } 
          }
      }); 
   }
} 

Creating a History Record 

The following Java action creates a history record and relates it to the current object, which is a contact record. This action would be executed whenever a contact's name is updates.

Business Rule

If the name of a contact modifies, write the following information to the contact History, under the Data Change category:

  • Old name of the contact.
  • New name of the contact.
  • Date when the change occurred.
  • ID of the user who made the change.

Action

Create a new history record with the following information in its fields:

Text: Contact name changed from <old name> to <new name>. Changed by
<user ID>.

Note: The date of the change was made is automatically recorded in the Created On system field of the history record.

Default Category: Data Change

Parent: Contact record where name change took place.

Entered by: User who made the change.

Sample Values

Object Definition:
contact (system object Contact)

Categories:
HIST_DACH (category of History)

Custom Fields:
None

Java Action: Creating a History Record 

public class CreatingAHistoryRecord extends CustomAction<Contact> {

    @Override
    public void action(final Contact contact) {
// Run as system user platform.getUtilityService().runAsSystemUser(new Callable() {
        @Override
            public void call() {
                // Get old contact
                final Contact oldContact = 
                platform.getContactService().readLastSaved(contact);
                
                // Create a string for history text using old and new values of the contact's name
                String historyText = String.format("Contact name changed from %s to %s",
                oldContact.getDisplayString(), contact.getDisplayString());
                
                // Create a history record and related it to the contact
                History history = platform.getHistoryService().newHistory(historyText, contact);
                
                // Set the primary category of the history to Data Change 
                history.setPrimaryCategory("HIST_DACH");
            }
        });
    }
}

Updating Added Categories 

The following Java action removes specific categories from the current object record and adds other categories.

In this example, when the value of the Pre/Post custom field in a claim record updates, the corresponding Pre or Post category is added. Each project can have only one of the two categories at a time. This action automatically sets the categories according to the value in the Pre/Post field.

Business Rule

When the Pre/Post field value updates, the corresponding Pre or Post category is added to a Claim project. Each project can have only one of the two categories at a time.

Action

Delete the old category and add the new category.

Sample Values

Object Definition:
CLAM (custom object Claim)

Categories:
CLAM (root category of Claim)
CLAM_POST
CLAM_PREE

Custom Fields:
PrePost (List)

Custom Field Value:
PRPO_ROOT_PREE (full tree position of lookup item)

Java Action: Updating Added Categories 

package com.mitratech.teamconnect.enterprise.api.model.rule;
import com.mitratech.teamconnect.enterprise.api.callable.Callable; 
import com.mitratech.teamconnect.enterprise.api.model.Project; 
public class UpdatingAddedCategories extends CustomAction<Project> {
    @Override
    public void action(final Project record) {
        // The record must be declared as final if it is going to be referenced in a Callable
        // Get an instance of the utility service in order to run code as system user
        platform.getUtilityService().runAsSystemUser(new Callable() { 
            public void call() {
                // Getting the value of the Pre/Post custom field
                String newPrePostKey = record.getProjectFieldValue("CLAM", "PrePost").getUniqueKey();
                if (newPrePostKey.equals("PRPO_ROOT_PREE")) { record.removeCategory("CLAM_POST"); 
                    record.addCategory("CLAM_PREE"); } 
                else {
                    record.removeCategory("CLAM_PREE");
                    record.addCategory("CLAM_POST"); 
                }
            } 
        });
    } 
} 

Checking and Setting Values in Custom Fields of Type List 

The following Java action automatically sets the value of one custom field according to the value selected in another custom field.

Business Rule

If the value in the Ice Cream custom field is Chocolate Cake, Chocolate Chip Cookie Dough, Moose Tracks, or Chocolate Peanut Butter, select Good in the Tastiness custom field. Otherwise, select Okay.

Action

Set the Tastiness custom field value to Good or Okay.

Sample Values

Object Definition: project (custom object) Custom Fields: icecream (List) Tastiness (String)

Custom Field List Values:

In custom lookup table icecream:

  • ICRM_ROOT_CHOC_CAKE
  • ICRM_ROOT_CCHP_CDGH
  • ICRM_ROOT_MOOS_TRKS
  • ICRM_ROOT_CHOC_PBTR

In custom lookup table Tastiness:

  • Good
  • Okay

Java Action: Checking and Setting Values in Custom Fields of Type List 

public class IceCreamCondition extends CustomCondition<Project> {
    @Override
    public boolean condition(Project project) {
        // Getting the value of the ice cream custom lookup field
        String flavor = project.getLookupFieldValue("icecream").getKey();
        /* Check whether the value of the field is one of the four ice cream flavors that contains chocolate */
        if (flavor.equals("CHOC_CAKE") || flavor.equals("CCHP_CDGH") || 
        flavor.equals("MOOS_TRKS") || flavor.equals("CHOC_PBTR")) {
            // If value is one of the four values, set "Tastiness" custom field to Good.
            project.setTextFieldValue("Tastiness", "Good"); } 
        else {
            // If value is NOT one of the four values, set "Tastiness" custom field to Okay.
            project.setTextFieldValue("Tastiness", "Okay"); 
        }
            
        /* This code can also be done without using keys, such as getting the value of a text field 
        which is not going to have a key associated with it. */
        
        // Getting the value of the ice cream custom lookup field String flavorText = project.getTextFieldValue("icecream");
        /* Check whether the value of the field is one of the four ice cream flavors that contains chocolate */
        return (flavorText.equals("CHOCOLATE CAKE") || flavorText.equals("CHOCOLATE CHIP COOKIE DOUGH") || 
        flavorText.equals("MOOSE TRACKS") || flavorText.equals("CHOCOLATE PEANUT BUTTER"));
    } 
} 

Creating Related Task Record 

The following Java action creates a task record, relates it to the current object, and sets the default category. The due date of the task is set to 15 days before the date in a custom field in the current object.

Business Rule

When the Trial Date field in a matter record updates with a value, create a task for the main assignee to complete the executive summary, with the due date 15 days before the trial date.

Action

Create a task with the following information in its fields:

Parent Project:
The Matter project

Assignee:
Main project assignee

Due On:
15 days before the trial date

Description:
Complete executive summary

Default Category:
Trial Preparation

Sample Values

Object Definition:
MATT (custom object Matter) 

Related Object Created: 
Task (system object) 

Categories:
MATT (root category of Matter)
TASK_TRPR (Task category) 

Custom Fields:
trialDate (Date field in Matter, created under the root category)

Java Action: Creating Related Task Record 

public class CreatingRelatedTaskRecord extends CustomAction<Project> { 
    @Override
    public void action(final Project project) {
        // Run as system user to bypass security 
        platform.getUtilityService().runAsSystemUser(new Callable() {
            @Override
            public void call() {
                // Creating task and assigning it to main assignee of current object
                Task task = platform.getTaskService().newTask("Complete executive summary", 
                project.getMainAssignee().getUser());
                CalendarDate trialDate = project.getCalendarDateFieldValue("MATT", "trialDate");

                // Set the due on date to fifteen days before the trial date Calendar dueOn = Calendar.getInstance(); 
                dueOn.setTime(trialDate);
                dueOn.add(Calendar.DAY_OF_YEAR, -15); 
                task.setDueDate(new CalendarDate(dueOn));

                // Set primary category to trial preparation
                task.setPrimaryCategory("TASK_TRPR"); }
            }
        ); 
    }
}  

Parameterized Actions

Rule parameters appear in the user interface and allow the administrator to enter values for the rule. Having parameters in rules is useful when certain values in a qualifier or an action may change and you prefer to have the administrator change the value through the user interface rather than modify the file. Parameterized rules are also useful because you can use the same file for multiple rules that each require different values.

Parameters for a wizard page action work in the same way as a rule, expect they appear in the wizard.

This section includes the following parameterized action samples:

Specifying Due Date for Task Record Using Parameter 

The following sample automatically creates a task record when the user is saving a claim record for the first time. The due date of the task is set automatically according to the number of days specified by the administrator in the parameter, which appears as a field on the Rule screen in the user interface.

Business Rule

When the Police Report Issued checkbox is selected in a Claim, the system creates a task.

Action

Creates a task to obtain a copy of the report with the following information in its fields:

Parent Project: the Claim project.

Assignee: Main project assignee.

Description: Obtain a copy of the police report.

Default Category: Follow-up:FNOL.

Parameter: A Number field with the name "numberOfDaysAfter" and the label "The number of days between the date the claim was created and the due date"

Due On: Parameter numberOfDaysAfter.

Sample Values

Object Definition:
Claim or any custom object definition

Rule Parameter Created:
numberOfDaysAfter (Integer)

Related Object Created:
TASK (system object Task)

Categories in Related Object:
TASK_FLUP_FNOL Custom Fields: None

Java Parameterized Action: Specifying Due Date for Task Record Using Parameter 

public class SpecifyingDueDateForTaskRecord extends CustomAction<Project> {

    @Override
    public void declareParameters() {
        parameters.addNumberParameter("numberOfDaysAfter", "The number of days 
        between the date the claim was created and the due date", 
        Long.valueOf(1));
    }
    
    @Override
    public void action(final Project project) {
        // Run as system user to bypass security 
        platform.getUtilityService().runAsSystemUser(new Callable() {
            @Override
            public void call() {
                // Get the value of the rule parameter
                int numberOfDaysAfter = 
                parameters.getNumberParameterValue("numberOfDaysAfter").intValue() 
                ;
                
                // Create a task and assigning it to the main assignee of the project
                Task task = platform.getTaskService().newTask("Obtain a copy of the police report", 
                project.getMainAssignee().getUser());

                // Relate the task to the project 
                task.setProject(project); 
                
                // Set the due date based on the number of days specified in the rules parameter
                Calendar dueOn = Calendar.getInstance(); 
                dueOn.setTime(project.getCreatedOn()); 
                dueOn.add(Calendar.DAY_OF_YEAR, numberOfDaysAfter);
                
                // Set the primary category of the task
                task.setPrimaryCategory("TASK_FLUP_FNOL"); 
            }
        }); 
    }
} 

Creating Project with Related History Using Parameters 

The following Java action uses multiple parameters. Based on these parameter values, the action creates a Package Request custom object record. It then determines whether to create a related history record based on a boolean parameter, and if so, creates the history record with the correct values.

Business Rule

When the value in the Accident State custom field in a new Claim is New York, a letter Package Request project must be created to generate the appropriate notices for the insured and claimant.

Action

Create a Package Request with the following information:

Requested for: Claim record.

Parameter 1:
Text field named "categories" and labeled "Type the full tree position of the Letter Package Request categories, separated by commas:"

Parameter 2:
Number field with the name "numberOfDaysAfter" and the label "Type the number of days from the moment the rule is triggered to specify the date when the letters must be sent out:"

Parameter 3:
Check Box field with the name "isAuditCreated" and the label "Specify whether an audit file should be created for each request:"

Using Parameter 1, add the specified categories to the package request record.

Send Date: Parameter 2.

Create Audit File: Parameter 3.

  • If yes—create a history record with following data in its fields:
    Text: NY Package request generated.
    Default Category: Audit
    Parent: the Claim project.
    Entered by: TeamConnectAdmin.
  • If no—no other records are created.

Sample Values

Object Definition:
Claim or any custom object definition

Related Objects Created:
PKRE (custom object Package Request) TNHistory (the audit file)

Wizard Parameters: 
categories (Text) numberOfDaysAfter (Number) isAuditCreated (Check Box) 

Categories:
PKRE (root category of Package Request) HIST_AUDI (History category)

Custom Fields:

In PKRE:

requestedFor (custom field of type Custom Object, pointing to the same custom object definition as the one for which the rule is written)

sendDate (Date)

Java Parameterized Action: Creating Project with Related History Using Parameters 

public class CreatingProjectWithRelatedHistory extends CustomAction<Project> {
    
    @Override
    public void declareParameters() {
        parameters.addTextParameter("categories", "Full tree position of the Letter Package Request categories, 
        separated by commas", null);
        parameters.addNumberParameter("numberOfDaysAfter", 
        "Number of days between the rule triggering and the date the letters must be sent out", Long.valueOf(1)); 
        parameters.addBooleanParameter("isAuditCreated", "Whether an audit file should be created 
        for each package request", null);
    }
    
    @Override
    public void action(final Project project) {
        // Get the parameter values
        final int numberOfDaysAfter = parameters.getNumberParameterValue("numberOfDaysAfter").intValue();
        final boolean isAuditCreated = parameters.getBooleanParameterValue("isAuditCreated");
        final String[] categories = parameters.getTextParameterValue("categories").split(Pattern.quote(","));

        // Run as system user to bypass security platform.getUtilityService().runAsSystemUser(new Callable() {
            @Override
            public void call() {
                // Creating new package request
                Project packageRequest = platform.getProjectService().newProject("PKRE");

                // Setting value of Requested For custom field to the current project object
                packageRequest.setProjectFieldValue("PKRE", "requestedFor", project);

                for (String category : categories) { 
                    packageRequest.addCategory(category);
                }
                
                Calendar sendDate = Calendar.getInstance();
                sendDate.setTime(new Date());
                sendDate.add(Calendar.DAY_OF_YEAR, numberOfDaysAfter);
                packageRequest.setDateFieldValue("PKRE", "sendDate", sendDate.getTime());

                if (isAuditCreated) {
                    // Create history with primary category set to audit
                    History history = platform.getHistoryService().newHistory("Package request generated", project);
                    history.setPrimaryCategory("HIST_AUDI"); 
                }
            } 
        });
    }
}  

Wizard Page Actions

The construction of a wizard action is almost the same as the construction of a rule action, except the action identifies and uses parameters in different ways. For details about wizard page actions, see Wizard Automated Actions.

You can use the following examples of wizard page actions in Java. These actions execute when the wizard user clicks next to go to the next wizard page.

Creating a Child Project 

Automated actions in wizards can create related records for a main record. While you can also create related records through a template, by creating related records through a page action, you can specify that the related record only create when certain conditions exist.

In this example, when the Any Injuries? checkbox is selected in a wizard, the system creates a child BI Claim. The following wizard action automatically creates a child BI Claim project.

What User Does On Wizard Page

User selects the Any Injuries? checkbox (a wizard parameter of type Boolean) in the First Notice of Loss wizard

Wizard Page Action

Create a child Claim with the default category Bodily Injury

Sample Values

Object Definition:
CLAM (custom object Claim)

Categories:
CLAM_BOIN

Custom Fields:
None

Wizard Parameters:
anyInjury (boolean)

Java Wizard Action: Creating a Child Project 

public class CreatingAChildProject extends CustomAction<Project> {
    @Override
    public void action(final Project project) {
        // Get wizard parameter 
        final boolean isAnyInjury =
        parameters.getBooleanParameterValue("anyInjury");

    // Run as system user to bypass security 
    platform.getUtilityService().runAsSystemUser(new Callable() {

        @Override
        public void call() {
            // Create new claim as a child of the project
            Project claim = platform.getProjectService().newProject("CLAM"); 
            claim.setParentProject(project);

            // Add BI category as primary claim.setPrimaryCategory("CLAM_BOIN");
        }
     });
   }
}

Setting User with Specific Role in Project as Task Assignee 

The wizard action automatically assigns the task to the first user who has the Proposed Attorney assignee role in the matter.

What User Does On Wizard Page

User adds an assignee to the matter wizard.

Wizard Page Action

Checks the role of the assignee, and if a user has the Proposed Attorney role, add this user as the assignee to the template-created task record associated with the wizard.

Sample Values

Object Definition:
MATT (custom object Matter)

Assignee Roles:
MATT_PRAT (Proposed Attorney)

Categories:
None

Custom Fields:
None

Wizard Parameters: project (project) Related Object: 
task (a Task)

Java Wizard Action: Setting User w ith Specific Role as Assignee in Task 

public class SettingUserWithRoleAsAssigneeInRelatedTask extends CustomAction<Task> {

    @Override
    public void action(final Task task) {
        // Retrieve project wizard parameter
        final Project project = parameters.getProjectParameterValue("project");
        
        // Run as system user to bypass security platform.getUtilityService().runAsSystemUser(new Callable() {
            
            @Override
            public void call() {
                // Get list of project assignees
                List<ProjectAssignee> assignees = project.getAssignees();
                
                for (ProjectAssignee assignee : assignees) {
                    // Assign the project assignee with the 'Proposed Attorney' 
                    role
                    if (assignee.getAssigneeRole().equals("MATT_PRAT")) {
                        platform.getTaskService().reassign(task, assignee.getUser());
                        break;
                    }
                }
            }
        });
    }
}

Filtering Users for Manual Selection 

The following wizard page action assigns a list of users to a project when they have a certain primary category in their contact records.

What User Does On Wizard Page

User selects Bodily Injury as the default category for a claim record.

Wizard Page Action

Selects all BI adjusters and lists them as assignees on the project.

Sample Values

Object Definition:
CLAM (custom object Claim)

Assignee Roles: 
ADJU (BI Adjuster) 

Categories:
CONT_ADJU_BIAD (category of Contact)

Custom Fields:
None

Wizard Parameters:
None

Java Wizard Action: Filtering Users for Manual Selection 

public class FilteringUsersForManualSelection extends CustomAction<Project> {

    @Override
    public void action(final Project project) {

        // Run as system user to bypass security platform.getUtilityService().runAsSystemUser(new Callable() {
            @Override
            public void call() {
                List<User> users = platform.getUserService().getAllUsers();

                for (User user : users) {
                    // If the user's contact's primary category is BI Adjuster, add to adjusters
                    if 
                    (user.getContact().getPrimaryCategory().getTreePosition().equal s("CONT_ADJU_BIAD")) {
                        project.addAssignee("ADJU", user); }
                    } 
                }
            }); 
        } 
    }
}     

Automatically Selecting Project Assignees 

The following wizard page action first checks whether the claim record created by the wizard has the category BI. It then gets a list of users by checking the default category (Bodily Injury) and the value in the Is available checkbox in the user's contact record. The action also assigns the first available BI Adjuster to the claim and then clears the Is available checkbox.

What User Does On Wizard Page

User adds the Bodily Injury category to a claim record created through a wizard.

Wizard Page Action

Assigns the first available BI Adjuster to the claim by checking the default category (Bodily Injury) and the value in the Is available checkbox in the user's contact record. Then, clears the Is available checkbox.

Sample Values

Object Definition:
CLAM (custom object Claim) 

Assignee Roles: 
CLAM_ADJU (Claim Adjuster) 

Categories:
CLAM_BDIN (category in Claim)
CONT_ADJU_BIAD (category in Contact)
CONT_ADJU (category in Contact) 

Custom Fields:
isAvailable (checkbox in Contact)

Wizard Parameters:
None

Java Wizard Action: Automatically Selecting Project Assignees 

public class AutomaticallySelectingProjectAssignee extends CustomAction<Project> {

    @Override
    public void action(final Project project) {
        try {
            platform.getUtilityService().runAsSystemUser(new CallableWithException<Exception>() { 

            @Override
            public void call() throws Exception {
                // Check whether BI Category has been added to the claim record boolean isBI = 
                project.hasCategory("CLAM_BDIN");

                // Get all users
                List<User> users = platform.getUserService().getAllUsers();

                for (User user : users) {
                    // Check primary category and value of Is Available field on each user's contact
                    Contact contact = user.getContact();
                    if (contact.getPrimaryCategory().equals("CONT_ADJU_BIAD") && 
                    contact.getBooleanFieldValue("CONT_ADJU", "isAvailable")) {
                        // Add the user as a project assignee with the role BI Adjuster
                        project.addAssignee("CLAM_ADJU", user);

                        // Make the contact no longer available
                        contact.setBooleanFieldValue("CONT_ADJU", "isAvailable", false);
                    } 
                }
            } 
        });
    } catch (Exception e) {
        // Log a message with the exception attached
        logWarn("The category CLAM_BDIN was not added to Claim", e);
    } 
  }
} 
  • Was this article helpful?