Friday, December 19, 2014

How to get task details for a given task-id

Problem Statement :
  You want to get details about a task. You know the task id and you would like to fetch details like who is holding the task, who assigned this task, if its open or closed, the task subject, priority etc.

Solution :
  Use the following code. You need to have an input variable as tw.local.taskId (String) that has the task-id and an output variable of type BPM_Task. BPM_Task has the following simple variables in it:
  •   taskId (String)
  •   assignedUser (String)
  •   receivedFromUser (String)
  •   closedByUser (String)
  •   assignedGroup (String)
  •   status (String)
  •   subject (String)
  •   priority (String)
  •   receivedDate (Date)
  •   receivedDateString (String)
  •   dueDate (Date)
  •   dueDateString (String)
  •   readDate (Date)
  •   readDateString (String)
  •   closeDate (Date)
  •   closeDateString (String)
  •   instanceId (String)
var twSearch = new TWSearch();

var taskId = new TWSearchColumn();
taskId.type = TWSearchColumn.Types.Task;
taskId.name = TWSearchColumn.TaskColumns.ID;

var taskAssignedToUser = new TWSearchColumn();
taskAssignedToUser.type = TWSearchColumn.Types.Task;
taskAssignedToUser.name = TWSearchColumn.TaskColumns.AssignedToUser;

var taskReceivedFromUser = new TWSearchColumn();
taskReceivedFromUser.type = TWSearchColumn.Types.Task;
taskReceivedFromUser.name = TWSearchColumn.TaskColumns.ReceivedFrom;

var taskClosedByUser = new TWSearchColumn();
taskClosedByUser.type = TWSearchColumn.Types.Task;
taskClosedByUser.name = TWSearchColumn.TaskColumns.ClosedBy;

var taskAssignedToRole = new TWSearchColumn();
taskAssignedToRole.type = TWSearchColumn.Types.Task;
taskAssignedToRole.name = TWSearchColumn.TaskColumns.AssignedToRole;

var taskStatus = new TWSearchColumn();
taskStatus.type = TWSearchColumn.Types.Task;
taskStatus.name = TWSearchColumn.TaskColumns.Status;

var taskSubject = new TWSearchColumn();
taskSubject.type = TWSearchColumn.Types.Task;
taskSubject.name = TWSearchColumn.TaskColumns.Subject;

var taskPriority = new TWSearchColumn();
taskPriority.type = TWSearchColumn.Types.Task;
taskPriority.name = TWSearchColumn.TaskColumns.Priority;

var taskReceivedDate = new TWSearchColumn();
taskReceivedDate.type = TWSearchColumn.Types.Task;
taskReceivedDate.name = TWSearchColumn.TaskColumns.ReceivedDate;

var taskDueDate = new TWSearchColumn();
taskDueDate.type = TWSearchColumn.Types.Task;
taskDueDate.name = TWSearchColumn.TaskColumns.DueDate;

var taskReadDate = new TWSearchColumn();
taskReadDate.type = TWSearchColumn.Types.Task;
taskReadDate.name = TWSearchColumn.TaskColumns.ReadDate;

var taskCloseDate = new TWSearchColumn();
taskCloseDate.type = TWSearchColumn.Types.Task;
taskCloseDate.name = TWSearchColumn.TaskColumns.ClosedDate;

var instanceId = new TWSearchColumn();
instanceId.type = TWSearchColumn.Types.ProcessInstance;
instanceId.name = TWSearchColumn.ProcessInstanceColumns.ID;

twSearch.columns = new Array(taskId, taskAssignedToUser, taskReceivedFromUser, taskClosedByUser, taskAssignedToRole, taskStatus, taskSubject, taskPriority, taskReceivedDate, taskDueDate, taskReadDate, taskCloseDate, instanceId);

var searchCondition = new TWSearchCondition();
searchCondition.column = taskId;
searchCondition.operator = TWSearchCondition.Operations.Equals;
searchCondition.value = tw.local.taskId;

twSearch.conditions = new Array(searchCondition);

twSearch.organizedBy = TWSearch.OrganizeByTypes.Task;

var results = twSearch.execute();

if(results && results.rows && results.rows.length == 1) {
    var row = results.rows[0];
   
    tw.local.taskDetails = new tw.object.BPM_Task();
    tw.local.taskDetails.taskId = row.values[0].toString();
    tw.local.taskDetails.assignedUser = row.values[1]?row.values[1].toString():null;
    tw.local.taskDetails.receivedFromUser = row.values[2]?row.values[2].toString():null;
    tw.local.taskDetails.closedByUser = row.values[3]?row.values[3].toString():null;
    tw.local.taskDetails.assignedGroup = row.values[4]?row.values[4].toString():null;
    tw.local.taskDetails.status = row.values[5]?row.values[5].toString():null;
    tw.local.taskDetails.subject = row.values[6]?row.values[6].toString():null;
    tw.local.taskDetails.priority = row.values[7]?row.values[7].toString():null;
    tw.local.taskDetails.receivedDate = row.values[8]?row.values[8]:null;
    tw.local.taskDetails.receivedDateString = tw.local.taskDetails.receivedDate?tw.local.taskDetails.receivedDate.format('MM/dd/yy hh:mm:ss aaa'):null;
    tw.local.taskDetails.dueDate = row.values[9]?row.values[9]:null;
    tw.local.taskDetails.dueDateString = tw.local.taskDetails.dueDate?tw.local.taskDetails.dueDate.format('MM/dd/yy hh:mm:ss aaa'):null;
    tw.local.taskDetails.readDate = row.values[10]?row.values[10]:null;
    tw.local.taskDetails.readDateString = tw.local.taskDetails.readDate?tw.local.taskDetails.readDate.format('MM/dd/yy hh:mm:ss aaa'):null;
    tw.local.taskDetails.closeDate = row.values[11]?row.values[11]:null;
    tw.local.taskDetails.closeDateString = tw.local.taskDetails.closeDate?tw.local.taskDetails.closeDate.format('MM/dd/yy hh:mm:ss aaa'):null;
    tw.local.taskDetails.instanceId = row.values[12]?row.values[12].toString():null;
}

Friday, November 7, 2014

Advance a Oracle Sequence to match the corresponding column maximum

Problem Statement :

You have a Oracle sequence that is lagging behind a columns value. That column is supposed to have unique values and when it tries to derive the value using the sequence it fails. Hence you would like to have a quick and dirty method to advance the value of the sequence to match the column's value.

Solution :

        declare
          i           INTEGER;
          max_row_id  INTEGER;
        BEGIN
          select  MAX(<COLUMN_NAME>) INTO max_row_id
          FROM <TABLE_NAME>;
         
          DBMS_OUTPUT.PUT_LINE ('Max row id :' || max_row_id);
         
          select <SEQUENCE_NAME>.nextval INTO i from dual;
         
          DBMS_OUTPUT.PUT_LINE ('Starting with Sequence value :' || i);
         
          loop
            if i>=max_row_id then
              EXIT;
            else
              select
<SEQUENCE_NAME>.nextval INTO i from dual;
            end if;     
          end loop;
         
          DBMS_OUTPUT.PUT_LINE ('Ending with Sequence value :' || i);
        END;

Wednesday, September 17, 2014

Passing individual elements of list into multi-instance loop

Problem Statement

You have an activity that is implemented as a multi-instance loop. You want to pass each instance of the task a different data object to work on. You have sorted all the objects into a list. Now, you need to pick the appropriate object from the list and pass them into the individual tasks created by the multi-instance loop.

Solution

Use tw.system.step.counter. This holds the value of the loop counter in the multi-instance loop.

Friday, August 22, 2014

Run Task in Debug Mode on an offline Process Server

Problem Statement
Run a task in debug mode. This is useful if you are trying to debug an issue and want to go through individual steps. This is a trivial step in an online process server, but if the process-server is not connected to the Process Designer, this work around solution might help you.

Solution
Get the task ID.
Replace the task id and server host-name in the URL below.
https://<HOSTNAME>/teamworks/process.lsw?zWorkflowState=1&zTaskId=2078.<TASK ID>&zDbg=1

Monday, August 18, 2014

Bulk Delete BPD Instances in IBM BPM 7.5

Problem Statement
How do I delete a large number of instances for a given BPD in IBM BPM 7.5.

Solution
  1. Start by finding the BPD Reference Number of the BPD (whose instances you want to purge). This can be located at "BPD_REF" column of "LSW_BPD_INSTANCE" table.
  2. Use the PL SQL block provided below to purge the BPD Instances. Supply the BPD Reference at the appropriate position.

DECLARE
  BPDINSTANCEID NUMBER;
  CURSOR instancesToDelete (bpdRef IN NUMBER) IS
    SELECT BPD_INSTANCE_ID
    FROM LSW_BPD_INSTANCE
    WHERE BPD_REF = bpdRef;
BEGIN
  BPDINSTANCEID := NULL;
  OPEN instancesToDelete(<BPD REFERENCE NUMBER>); 

  LOOP

    FETCH instancesToDelete  INTO BPDINSTANCEID;

    EXIT WHEN instancesToDelete%NOTFOUND;

    LSW_BPD_INSTANCE_DELETE(
      BPDINSTANCEID => BPDINSTANCEID
    );

  END LOOP;

END;

Thursday, May 29, 2014

Linux Directory Tree

Problem Statement
Print a tree structure showing all the files and directories under the current directory.

Solution
 find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'

CRONTAB - Quick Reference

Crontab Commands
crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.

Crontab syntax
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
  
Crontab Example
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

     30     18     *     *     *         rm /home/someuser/tmp/*
  
Disable Email
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line.

 
    >/dev/null 2>&1

Generate log file
To collect the cron execution execution log in a file :
 
    30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log