<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to dynamically start a task from a process that was started from an HTML Dialog</title><link>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog</link><description>&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;In a JSF Dialog we can start a task dynamically with: &lt;/p&gt;&lt;pre&gt;&lt;code&gt;FacesContext.getCurrentInstance().getExternalContext().redirect(ivy.html.taskstartref(ivy.wf.findTask(95)));&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We can also start an IProcess dynamically with something like that:
&lt;/p&gt;&lt;pre&gt;&lt;code&gt;IRequest request = requestFactory.createRequest(processStart, thisMapOrEmptyMapIfNull(params)); 
IResponse response = responseFactory.createResponse(); 
IRequestHandler requestHandler = (IRequestHandler)processStart.getProcessModelVersion().getAdapter(IProcessEngine.class); 
requestHandler.handleRequest(request, response);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now we would like to combine both to start a process dynamically that should in turn start a task.
The process can be started from within the JSF Dialog.&lt;br&gt;
In the started process, as we are not in the JSF context, the following does not work (fails silently):&lt;/p&gt;&lt;pre&gt;&lt;code&gt;FacesContext.getCurrentInstance().getExternalContext().redirect(ivy.html.taskstartref(ivy.wf.findTask(95)));&lt;/code&gt;&lt;/pre&gt;
The following code does not work as well (fails silently):&lt;pre&gt;&lt;code&gt;IHttpResponse resp = ivy.response as IHttpResponse;
resp.sendRedirect(ivy.html.taskstartref(in.task));&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We tried also:
&lt;/p&gt;&lt;pre&gt;&lt;code&gt;IHttpResponse resp = ivy.response as IHttpResponse;
HttpServletResponse sresp = resp.getHttpServletResponse();
sresp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
sresp.setHeader("Location",ivy.html.taskstartref(in.task));
sresp.sendRedirect(ivy.html.taskstartref(in.task));
sresp.flushBuffer();&lt;/code&gt;&lt;/pre&gt;
Here we get:&lt;br&gt;
IllegalStateException: Cannot change buffer size after data has been written&lt;br&gt;
Cannot set content type. Response already committed&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Is there a possibility to achieve what we try to do?
Like for the process-start I have tried to find a proper IRequestHandler for starting a task. I have not found it.&lt;/p&gt;
&lt;p&gt;Thanks a lot in advance&lt;/p&gt;
&lt;p&gt;Emmanuel&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog" rel="self"></atom:link><language>en</language><lastBuildDate>Sun, 05 Jul 2015 22:39:18 -0400</lastBuildDate><item><title>Answer by Emmanuel</title><link>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog/1390</link><description>&lt;p&gt;Hello Flavio,&lt;/p&gt;
&lt;p&gt;Thanks for your help, so I post the solution for others here.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;in our HTML Dialog we trigger the process start with our ProcessStarter and pass the TaskId to start as parameter&lt;/li&gt;
&lt;li&gt;The process retrieves the task start url with &lt;code&gt;[out.redirectUrl = ivy.html.taskstartref(in.task);]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;At the end of the process there is an End Page that points to a "redirect-end-page.jsp" using this redirectUrl for redirecting the user automatically to the Task.
(&lt;code&gt;document.location.href='&amp;lt;%=redirectTask%&amp;gt;'&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Thanks again Flavio!&lt;/p&gt;
&lt;p&gt;Emmanuel&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emmanuel</dc:creator><pubDate>Sun, 05 Jul 2015 22:39:18 -0400</pubDate><guid>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog/1390</guid></item><item><title>Comment by Flavio Sadeghi on Emmanuel's question</title><link>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog#1388</link><description>&lt;p&gt;&lt;a href="http://answers.axonivy.com/users/28/emmanuel"&gt;&lt;a href="http://answers.axonivy.com/users/28/emmanuel"&gt;@Emmanuel&lt;/a&gt;&lt;/a&gt;: Why you can't use an End-Page for the redirect? The End Page does end the current running process and task properly. With a redirect in the middle of a process, the process is interrupted unexpected which (could) cause in unexpected behaviour/errors.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Wed, 01 Jul 2015 11:24:33 -0400</pubDate><guid>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog#1388</guid></item><item><title>Comment by Emmanuel on Emmanuel's question</title><link>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog#1387</link><description>&lt;p&gt;Hello Flavio,&lt;/p&gt;
&lt;p&gt;Sorry for that long and not very "understandable" question ;)
To make it short: is there a way to start a Task programmatically in such a situation:
1. The User clicks on a Displayed Task (HTML Dialog - JSF).
2. This triggers a Process Start dynamically, which gets as parameter the selected TaskId.
3. In this process we can find the Task with the TaskId and we would like to start it and display it to the user.
As the Task is started in a Process that is not part of the HTML-JSF Dialog Logic, using "redirect" techniques described in the question do not work.
Any Idea?&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emmanuel</dc:creator><pubDate>Mon, 29 Jun 2015 13:27:16 -0400</pubDate><guid>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog#1387</guid></item><item><title>Comment by Flavio Sadeghi on Emmanuel's question</title><link>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog#1385</link><description>&lt;p&gt;Hello Emmanuel, could you describe your use case? Basically I would suggest to use an End Page to forward a workflow/client to the next process.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Fri, 26 Jun 2015 14:49:32 -0400</pubDate><guid>https://answers.axonivy.com/questions/1383/how-to-dynamically-start-a-task-from-a-process-that-was-started-from-an-html-dialog#1385</guid></item></channel></rss>