Implement custom work queue
MyActivitySetEscalationWorkQueue
To create a custom work queue, implement a class that extends class WorkQueueBase.
Before you begin
MyWorkItem as
defined in Define custom work item MyWorkItem.Procedure
- Open Guidewire Studio
- In the Studio Project window, expand .
- Create a new package directory named workflow.
-
Within the workflow folder,
create a new Gosu class named
MyActivitySetEscalationWorkQueue. -
Populate this class with the following code.
package workflow uses gw.processes.WorkQueueBase uses gw.api.database.Query uses gw.api.database.Relop uses java.util.Iterator uses gw.transaction.Transaction uses gw.api.email.EmailUtil uses gw.pl.persistence.core.Bundle /** * An example of batch processing implemented as a work queue that sends email * to assignees of activities that have not been viewed for five days or more. */ class MyActivitySetEscalationWorkQueue extends WorkQueueBase <Activity, MyWorkItem> { /** * Let the base class register this type of custom process by * passing the process type, the entity type the work queue item, and * the target type for the units of work. */ construct () { super (typekey.BatchProcessType.TC_NOTIFYUNVIEWEDACTIVITIES, MyWorkItem, Activity) } /** * Select the units of work for a batch run: activities that have not been * viewed for five days or more. */ override function findTargets (): Iterator <Activity> { // Query the target type and apply conditions: activities not viewed for 5 days or more var targetsQuery = Query.make(Activity) targetsQuery.compare(Activity#LastViewedDate.PropertyInfo.Name, Relop.LessThanOrEquals, java.util.Date.Today.addBusinessDays(-5)) return targetsQuery.select().iterator() } /** * Write a custom work item */ override function createWorkItem (activity : Activity, safeBundle : Bundle) : MyWorkItem { var customWorkItem = new MyWorkItem(safeBundle) customWorkItem.Activity = activity return customWorkItem } /** * Process a unit of work: an activity not viewed for five days or more */ override function processWorkItem (workItem : MyWorkItem): void { // Get an object reference to the activity var activity = workItem.Activity // Send an email to the user assigned to the activity if (activity.AssignedUser.Contact.EmailAddress1 != null) { EmailUtil.sendEmailWithBody(null, activity.AssignedUser.Contact // To: null, // From: "Activity not viewed for five days", // Subject: "See activity " + activity.Subject + ", due on " + activity.TargetDate + ".") // Body: } // Update the escalation date on the assigned activity Transaction.runWithNewBundle( \ bundle -> { activity = bundle.add(activity) // add the activity to the new bundle activity.EscalationDate = java.util.Date.Today } ) // update the escalation date return } }
