# Create a case

**URL:** <https://community.ofelia.com/t/create-a-case/6018>\
**Category:** Q&A\
**Created:** [8 June 2015 08:47 UTC](https://community.ofelia.com/t/create-a-case/6018 "2015-06-08T08:47:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamudm](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mohamudm](https://community.ofelia.com/u/mohamudm)\
**Post date:** [8 June 2015 08:47 UTC](https://community.ofelia.com/t/create-a-case/6018/1 "2015-06-08T08:47:22Z")

</div>

I am new to Bonita. I am using Engine API with spring mvc. How to I initiate new case if I am using .bar file. I can start the process and process instance, but If I want to start another process using the same bar file, is not working. Thank you for help!.

---

<div class="post-metadata">

**Author:** ![carlos.oliveira\_1](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@carlos.oliveira\_1](https://community.ofelia.com/u/carlos.oliveira_1)\
**Post date:** [15 June 2015 18:13 UTC](https://community.ofelia.com/t/create-a-case/6018/2 "2015-06-15T18:13:24Z")

</div>

Can you give more information about the problem and the code you are using?

---

<div class="post-metadata">

**Author:** ![mohamudm](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mohamudm](https://community.ofelia.com/u/mohamudm)\
**Post date:** [15 June 2015 18:44 UTC](https://community.ofelia.com/t/create-a-case/6018/3 "2015-06-15T18:44:34Z")

</div>

Thanks Carlos, I resolved that issue. Right now I am having taskinstance not found problem. It occur sometimes, other times it works. It seems to occur when I initiate executeTask method. After I execute, I can not get the next availabletask id so i can assign to a user. my app i am trying to auto assign the task after one task is completed.

The following code is what I am using to get TaskID.

public static long getFormReviewTaskPendingId(boolean action, long pID, String step) throws BonitaException, InterruptedException {  
Thread.sleep(4000); //add this, but it is inconsistent. works most of the time, but fails sometime. return task is 0  
long tID = 0;  
ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(BonitaHelper.getSession());  
SearchOptionsBuilder optionsBuilder = new SearchOptionsBuilder(STARINDEX, PAGE\_SIZE);  
[//optionsBuilder.sort](https://optionsBuilder.sort)(ArchivedProcessInstancesSearchDescriptor.SOURCE\_OBJECT\_ID, Order.ASC);  
SearchResult tasks = processAPI.searchMyAvailableHumanTasks(BonitaHelper.getSession().getUserId(), optionsBuilder.done());;  
for(HumanTaskInstance t : tasks.getResult())  
{  
if((t.getName().matches(“(?i)”+step+“-.\*”)) && (t.getParentContainerId() == pID) )  
{  
final long activityInstanceId = t.getId();  
[//processAPI.executeFlowNode](https://processAPI.executeFlowNode)(taskToExecute.getId());  
tID = activityInstanceId;  
break;  
}  
}  
return tID;  
}

public static void executeTask(long taskId) throws BonitaException{  
ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(BonitaHelper.getSession());  
HumanTaskInstance taskToExecute = processAPI.getHumanTaskInstance(taskId);   
processAPI.executeFlowNode(taskToExecute.getId());  
}

Thanks!
