I’m trying to create a task using the taskService and set an entryCriterion with an If_Part condition.
I already create the task but the problem is with the entryCriterion.
How can I create an entryCriterion and associate it with the created task?
That is not possible. The task you create via TaskService is not related to a CMMN plan item. However, sentries are based on plan items, i.e. they define when a plan item becomes available. CMMN has a concept for creating adhoc tasks, called discretionary tasks. That might be what you are interested in, yet, I am afraid that is not implemented.