How to initiate task for ad-hoc activitites in BPD of IBM BPM

We all know that we can create an ad-hoc task in an instance from the instance view of process portal. I have come across a scenario where I need to invoke an ad-hoc activity in the BPD programmatically instead of from instance view. After some research I found these two options using which we create an ad-hoc task for an ad-hoc activity in the BPD.
1. Using Rest API methods
2. Using js API (System API) from server script

In this post, let us look at system API method for invoking ad-hoc activity with name "Adhoc Update Request", which is created as a sub process in the BPD.

Before we start, we need to add Dashboards Toolkit to the Process Apps, as some of the object that we use is available in this toolkit.

    tw.local.activityName="Adhoc  Update Request";
    var activityListFilter=new tw.object.ActivityListFilter();
    activityListFilter.executionStateFilter=new Array("READY");
    activityListFilter.activityTypeFilter=new Array("SUB_PROCESS");
    var properties=new tw.object.ActivityListProperties();
    properties.filters=new tw.object.listOf.ActivityListFilter();
    properties.filters.insertIntoList(0, activityListFilter);
    var instance=tw.system.findProcessInstanceByID(tw.local.instanceId);
    var activities=instance.retrieveActivityList(properties, 100, 0, false).activities;
    for(var i=0; i < activities.listLength; i++){
         if(activities[i].name.indexOf(tw.local.activityName) > -1){
               tw.local.activityId= activities[i].id;


This will initiate a task for the ad-hoc Activity in the given process instance.

For more options on the above script, go through the below url:

Thanks for reading the post !!


No comments:

Post a Comment