Unfortunately it won't be possible in the EntryScript, as the task would not have been created at that point, and hence the Task ID would not have been generated yet. However, depending on exactly why and where you would like to retrieve the task from, you could consider the following approach which does not require a process variable to store the task ID at all:
You will find that the HumanTaskNodeInstance has a method getWorkItemId() which returns the Id of WorkItem used to create the Task with.
You can retrieve a task by its WorkitemId in
org.kie.api.task.TaskService.getTaskByWorkItemId().
Hence if you know which HumanTaskNodeInstance was used to create the task, you can find the associated Task.
A second approach would be to register a TaskLifeCycleEventListener and override afterTaskAdded, but then you do not have easy access to the ProcessInstance we could pose a challenge.
A third approach would be to implement your own HumanTask WorkItemHandler, but that seems a bit hard handed for the requirement at hand.
Let me know if the first approach does not work and we can explore one of the other two approaches.
Unfortunately it won't be possible in the EntryScript, as the task would not have been created at that point, and hence the Task ID would not have been generated yet. However, depending on exactly why and where you would like to retrieve the task from, you could consider the following approach which does not require a process variable to store the task ID at all:
A second approach would be to register a TaskLifeCycleEventListener and override afterTaskAdded, but then you do not have easy access to the ProcessInstance we could pose a challenge.
A third approach would be to implement your own HumanTask WorkItemHandler, but that seems a bit hard handed for the requirement at hand.
Let me know if the first approach does not work and we can explore one of the other two approaches.