AnsweredAssumed Answered

How to start the process only when the process is in saved or Complted mode?

Question asked by anitapatil.bld@gmail.com on May 8, 2018

Hi all,

 

I have process with 2 tasks namely t1 and t2. 


I have a case to start a process on clicking the app only when the process is in saved or completed mode, means if one process is already started if it is in running mode I should re direct it to task details page of t1 else i should start new process and then redirect to task details page of newly started process's t1 task. 


For this I have written code to start the process on click of app now it is started and redirecting to task details page.

Now I need to check the condition for the process status, for this have written code by identifying the process instance if length is > 0 i was redirecting it to previous task details page(it is k) else it should start the new process(it is working).

But Once you complete the task t1 am getting data[0] undefined. Can any one give me the solution for it?

 

My code is as follows

 

onAppClickStartProcess(app: AppDefinitionRepresentationModel) {
//this.apppid1 = app.id;
this.processService.getProcessDefinitions(app.id).subscribe(
data => {
this.apppid = data;
//exdepid means process defination id
this.exdepId = this.apppid[0].id;
this.processService.getProcessInstances({
appDefinitionId: app.id,
state: "all"
}).subscribe(
data=>{
console.log("******taskkkk*******")
console.dir(data)
// console.log("previus data="+data[0].id);
console.log("*****taskkkkkk********")
if(data.length>0){
console.log("in if");
this.processService.getProcessTasks(data[0].id, "all").subscribe(
data => {
console.log("*****previous task id******");
console.dir(data);
console.log("*****previous task id******");
this.router.navigate(['app-list/apps', app.id || 0, 'tasks', data[0].id]);
});
}

else {
console.log("in else");
this.processService.startProcess(this.exdepId, "AppName", "", "")
.subscribe((processInstance: ProcessInstance) => {
this.processService.getProcessTasks(processInstance.id, "all").subscribe(
data => {
console.log("***********");
console.dir(data);
console.log("***********");
this.router.navigate(['app-list/apps', app.id || 0, 'tasks', data[0].id]);
});
}, error => {
console.log('Error: ', error);
});
}
});
});
}

}

Outcomes