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

Wednesday, May 28, 2014

Adhoc Service Call in IBM BPM 7.5

Problem Statement 

You want to call a service residing outside of your toolkit/process-app. You know the name of the service, the process-app/toolkit acronym and possibly the snapshot name as well. You want to discover the service and execute it without having to go through the process of creating dependencies within your toolkit/process-app. Traditionally this is not possible, IBM BPM 7.5 provides API to call any service from JavaScript (Using tw.system.executeServiceByName()), but this can only execute the services that directly belong to the process-app/toolkit or any dependent toolkit(s). We want to break free of this limitation and execute any service on the environment.

Solution
Create a new Server-JS file and copy the following functions into it.
function findSnapshotForProcessApp(processApp, snapshotName) {
    var processAppObj = null;
    if(typeof processApp == 'string')
        processAppObj = tw.system.model.findProcessAppByAcronym(processApp);

    try {
        if(snapshotName) {
            return processAppObj.findSnapshotByName(snapshotName);
        }
        else {
            var snaps = processAppObj.snapshots;
            if(snaps && snaps.length > 0)
                return snaps[snaps.length -1];
            else
                return null;
        }
    }
    catch (e) {
      throw 'Error in findSnapshotForProcessApp : Required parameter "processApp" not provided or an invalid process-app acronym was provided.';
    }
}
function executeServiceByNameAdHoc(serviceName, inputParams, processApp, snapshotName) {
    var snapshot = findSnapshotForProcessApp(processApp, snapshotName);
   
    if(snapshot) {
        var serv = snapshot.findServiceByName(serviceName);
        if(serv) {
            return serv.execute(inputParams);
        }
        else // Service not found
           throw 'Error in executeServiceByNameAdHoc : No service found. Parameters provided : processApp=' + processApp + ", snapshotName=" + snapshotName + ", serviceName=" + serviceName;
       
    }
    else // Snapshot not found
        throw 'Error in executeServiceByNameAdHoc : No snapshot found. Parameters provided : processApp=' + processApp + ", snapshotName=" + snapshotName;
}

Call the function executeServiceByNameAdHoc with the following parameters to execute any adhoc service.

* @param {String} serviceName The name of the service to execute
* @param {Map} inputValues the input values for the service
* @param {String} processApp : The Acronym for the process app in which the service resides.
* @param {String} (OPTIONAL) snapshotName : Name of the specific snapshot version to execute the service from.
*
* @return A map of output values
* @type Map

Issues

If you get a "ConcurrentModificationException" while trying to execute a service with multiple parameters, the go ahead and deploy the IBM APAR JR49178. This fixes a bug related to HashMap in the method com.lombardisoftware.core.script.js. TWServiceScriptable.jsFunction_execute(Object)