Useful apis and script to start BPD in IBM BPM

When a bpd is created In the overview instance name, to get instanceID

“Customer Process:” + tw.system.process.instanceId

To start a bpd using service

tw.local.inputValues=new tw.object.Map();
tw.local.inputValues.put('idjRequest', tw.local.idjRequest); //BPD input variable.var name in bpd
tw.local.instanceID = tw.system.startProcessByName('CustomerProcess',tw.local.inputValues,true).id;
    var id = [1];
    if (tw.local.instanceID != null && tw.local.instanceID != '') {
        id= tw.local.instanceID.split(".");
    }
    tw.local.response = id[1];
 log.info("Exit Service by triggering BPM Instance ID:- " + " " + tw.local.instanceID);

To call the service
https://10.0.10.208:9444/rest/bpm/wle/v1/service/servicename?action=start&params=”+requestdata

To get the current instance ID

In your script:

tw.local.instanceid = tw.system.currentProcessInstance.id;
var id = [1];
if(tw.local.instanceid !=null &&tw.local.instanceid !=’’){
id=tw.local.instanceid.split(.);
}
tw.local.instanceid = id[1];

To terminate a bpm instance:

tw.system.findProcessInstanceByID(instanceid).abort();

API to get logged in user name:

tw.system.user.name

API to get all the teams user is in:

tw.system.user.teams

Script to check whether there is any active instance for a specific unique field in request using search column api. Here my unique id which Im searching is loanRef

log.info("----Validate Loan Reference existence for loan ref----" + tw.local.loanRef);
var col1 = new TWSearchColumn();
col1.name = TWSearchColumn.ProcessInstanceColumns.ID;
col1.type = TWSearchColumn.Types.ProcessInstance;

var col2 = new TWSearchColumn();
col2.name = TWSearchColumn.ProcessColumns.Name;
col2.type = TWSearchColumn.Types.Process;

var col3 = new TWSearchColumn();
col3.name = TWSearchColumn.ProcessInstanceColumns.Status;
col3.type = TWSearchColumn.Types.ProcessInstance;

var searchCondition = new TWSearchCondition();

var mySearchCol2 = new TWSearchColumn();
mySearchCol2.type = TWSearchColumn.Types.BusinessData;

mySearchCol2.name = "loanRef";
searchCondition.column = mySearchCol2;

searchCondition.operator = TWSearchCondition.Operations.Equals;
searchCondition.value = tw.local.loanRef;

// Search Ordering
var order1 = new TWSearchOrdering();
order1.column = col2;
order1.order = TWSearchOrdering.Orders.Descending;

// Create search object and set values
var search = new TWSearch();

search.columns = [col1, col2, col3];
search.organizedBy = TWSearch.OrganizeByTypes.ProcessInstance; //Task;
search.conditions = new Array(searchCondition);

// EXECUTE THE SEARCH IN THE CONTEXT OF USER change the limit of 20 as desired
var results = search.execute();

log.info('***print results length:- '+results.rows.length);

tw.local.results = new tw.object.listOf.BusinessReport();

if (results != null && results.rows != null && results.rows.length > 0) {
    log.info("Results not null and row length = " + results.rows.length);
    for (var i = 0; i < results.rows.length; i++) {
        var task = new tw.object.BusinessReport();
        task.id = results.rows[i].values[0];
        task.name = results.rows[i].values[1];
        task.status = results.rows[i].values[2];
        tw.local.results[i] = task;
     log.info("Instance Id: " + results.rows[i].values[0]);
     log.info("Process Name: " + results.rows[i].values[1]);
     log.info("Status: " + results.rows[i].values[2]);
    } //for
} //if
var len = tw.local.results.listLength;
if (tw.local.results != null && len > 0) {
    for (var i = 0; i < len; i++) {
        if (tw.local.results[i].status != "Completed") {
            tw.local.response = true;
            log.info("***Ref exists for PIID: " + tw.local.results[i].id);
        } else {
            tw.local.response = false;
            log.info("***Ref does NOT exists in BPM database***");
        }
    }
} else {
    tw.local.response = false;
    log.info("**Ref does NOT exists and executed in else loop ***");
}
log.info("Response Sent for IDJ: " + tw.local.response);
Advertisements