Purpose -
The purpose of this article to provide instructions for how to create a rule that sends notifications to a user's email address based on a custom field versus a static email address.
Required permissions -
DROOLS_CREATION_RULE (to create a custom rule using the drools editor)
SYSTEM_SETTINGS_UPDATE (to create a custom field)
Instructions -
Pre-requisites:
Your tenant has a custom field already present on the project details (or main) interface that is either a text field or user type. If you need assistance creating a custom field, please review this article - How to create a custom field/custom field type/custom field group.
Instructions:
1. Create a new drool from the rules editor interface and place in an appropriate library.
2. Place the rule in the "workflow" module.
3. Provide a Resource name. This is the name of the rule.
4. Copy the below drool syntax into the content section of the drool.
package com.iriusrisk.drools;
import com.iriusrisk.drools.model.*;
import com.iriusrisk.drools.model.riskpattern.*;
import com.iriusrisk.model.*;
import com.iriusrisk.*;
import com.iriusrisk.drools.fact.*;
import com.iriusrisk.factories.DroolsValueConverter;
import com.iriusrisk.utils.EntityWithUDTUtil;
import com.iriusrisk.drools.fact.TagFact;
// Name for my rule
rule "Workflow Testing"
no-loop
salience 9000
when
$project : ProjectFact();
// watch the current workflow state
$workflowState : WorkflowStateFact() @watch ( !currentWorkflowState );
// triggers whenever it transitions to the next workflow state
UserEvent(type == "EVENT_NEXT_WORKFLOW_STATE");
// your custom field value
ProjectCustomFieldFact(uniqueId == "User", hasValue("!=", "")) @Watch(value);
// your custom field value
$pcf : ProjectCustomFieldFact(uniqueId == "User")
then
// your action which is to send that user this email
// the message could also be a dynamic and would required its own custom field
insertLogical(new NotifyUserActionEvent($project.getUniqueId(), "EMAIL", $pcf.getValue(), "Workflow Notification", "Workflow has been updated"));
end
This workflow rule functions based on when the workflow advances to the next workflow state. You could also add in additional conditions for reversal and it would look like this for that line:
UserEvent(type == "EVENT_NEXT_WORKFLOW_STATE") || UserEvent(type == "EVENT_PREVIOUS_WORKFLOW_STATE");
This creates an OR statement which now lets you alert on if the workflow notification moves forward or backward.
5. If you need to notify when it enters into a certain flow state, you would use the following condition instead:
WorkflowStateFact((currentWorkflowState != null && currentWorkflowState.uniqueId == "archived")
It is possible to create multiple OR statements on that condition to get the notification from multiple workflow states. Alternatively, permissions could be revoked that prevent users from skipping to non-sequential workflow states. Removing the permission set WORKFLOW_ALL_CHANGE would restrict the user from only moving the workflow one stage at a time.
Additionally, if you wanted to include the workflow state in the body of the email, you could also use the following rule to accomplish this.
// Place this rule in the "workflow" module in the drools editor.
package com.iriusrisk.drools;
import com.iriusrisk.drools.model.*;
import com.iriusrisk.drools.model.riskpattern.*;
import com.iriusrisk.model.*;
import com.iriusrisk.drools.fact.*;
import com.iriusrisk.factories.DroolsValueConverter;
import com.iriusrisk.utils.EntityWithUDTUtil;
import com.iriusrisk.drools.fact.TagFact;
rule "Workflow Trial"
no-loop
salience 9000
when
$project : ProjectFact()
// watch the workflow state
$workflowState : WorkflowStateFact() @watch ( !currentWorkflowState );
// substitute the custom field "workflow-testing" for your custom field that will contain the email address to send the notification to
ProjectCustomFieldFact(uniqueId == "workflow-testing", hasValue("!=", "")) @Watch(value);
UserEvent(type in ("EVENT_NEXT_WORKFLOW_STATE", "EVENT_PREVIOUS_WORKFLOW_STATE"));
$pcf : ProjectCustomFieldFact(uniqueId == "workflow-testing")
then
String msg = "Workflow state has been updated to " + $workflowState.getCurrentWorkflowState().getUniqueId() + " state";
insertLogical(new NotifyUserActionEvent($project.getUniqueId(), "EMAIL", $pcf.getValue(), "Workflow Change", msg));
end
Comments
0 comments
Please sign in to leave a comment.