1
0
-1

Hi Experts,

I am trying to abort a running process using beanshell code and change the status to Cancelled. The code is as below. This works when process id match the record id in the db. However, if the submission is already passed some time, I notice that Joget create a new process id which different from the origin. It will start a new process while aborting the origin process. Thus, when I run my beanshell code, it return error 'the process is already closed - can't abort it!'. Anyone can help?!


public void updateRecordValue(id){
String formDefId = "applyForm";
String fieldId = "status";
String fieldValue = "Cancelled";

AppDefinition appDef = AppUtil.getCurrentAppDefinition();
AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");

//retrieve data
FormRow row = new FormRow();
FormRowSet rowSet = appService.loadFormData(appDef.getAppId(), appDef.getVersion().toString(), formDefId, id);
if (!rowSet.isEmpty()) {
row = rowSet.get(0);
//update field value
row.setProperty(fieldId, fieldValue);
}

//Store the updated data
rowSet.set(0, row);
appService.storeFormData(appDef.getAppId(), appDef.getVersion().toString(), formDefId, rowSet, id);
}

public void terminateRunningInstance(id){
WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");

}

for(int i = 0; i < rowKeys.length; i++){
System.out.println("current key is " + rowKeys[i]);
String id = rowKeys[i];
updateRecordValue(id);
terminateRunningInstance(id);
}

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      However, if the submission is already passed some time, I notice that Joget create a new process id which different from the origin.

      From my experience, I think the process design has been changed under the same app version that caused this. You should take note and don't update the process design.

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi, perhaps you can try WorkflowManager#getWorkflowProcessLink to get a reference to the original process.

          CommentAdd your comment...