<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Start a process in plain Java</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java</link><description>&lt;p&gt;Is there a possibility to start a Xpert.ivy process from a Java bean in my ivy project? Either by calling a request start or a sub process...&lt;/p&gt;
&lt;p&gt;Something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;String signature = "myProcess()";
Set&amp;lt;IProcessStart&amp;gt; processes = ivy.wf.findProcessStartsBySignature(signature);
if(!processes.isEmpty()){
    IProcessStart process = processes.iterator().next();
    IProcessRequest request = RequestFactory.createProcessRequest(
        ivy.request.getProcessModelVersion(), process.getRequestPath(), 
        new HashMap&amp;lt;String, Object&amp;gt;()
    );
    try{
        // somehow send the request...
    }catch(Exception e){
        // do some exception handling if process fails...
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The main purpose is to be able to catch exceptions which may be thrown from the process. &lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/179/start-a-process-in-plain-java" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 18 Jun 2018 00:35:18 -0400</lastBuildDate><item><title>Answer by hungnam</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/3332</link><description>&lt;p&gt;Hello, is that possible to call a sub process which call another html dialog inside. E.g&lt;/p&gt;
&lt;p&gt;SubProcessCall.withPath("Functional Processes/callAnotherDialog").call();&lt;/p&gt;
&lt;p&gt;I tried it and got exception with number 1
ClassCastException: java.lang.Object cannot be cast to ch.ivyteam.ivy.scripting.objects.util.IIvyDataObject. 
Number 2 solution work well
&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/callSubProcess.png"&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">hungnam</dc:creator><pubDate>Mon, 18 Jun 2018 00:35:18 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/3332</guid></item><item><title>Comment by SupportIvyTeam on Daniel Oechslin's answer</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2621</link><description>&lt;p&gt;You can invoke methods from the HD logic by using the EL expression factory. Within the called method you could run the sub proces...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package test;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.MethodInfo;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

@ManagedBean
public class MyBean {

    public void doIt()
    {
        FacesContext context = FacesContext.getCurrentInstance();
        ExpressionFactory elFactory = context.getApplication().getExpressionFactory();
        ELContext elContext = context.getELContext();
        MethodExpression methodExpression = elFactory
                .createMethodExpression(elContext, "#{logic.fromBean2()}", String.class, new Class[0]);
        MethodInfo info = methodExpression.getMethodInfo(elContext);
        methodExpression.invoke(elContext, new Object[0]);
    }

}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Fri, 12 May 2017 04:18:31 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2621</guid></item><item><title>Comment by Stelt0 on Daniel Oechslin's answer</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2615</link><description>&lt;p&gt;I really want, but I`m on version 6.0&lt;/p&gt;
&lt;p&gt;Do I have alternative ?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stelt0</dc:creator><pubDate>Thu, 11 May 2017 08:25:09 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2615</guid></item><item><title>Comment by SupportIvyTeam on Daniel Oechslin's answer</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2614</link><description>&lt;p&gt;Try the new API above: SubProcessCall.... 
Does it work better?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Thu, 11 May 2017 08:13:59 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2614</guid></item><item><title>Comment by Stelt0 on Daniel Oechslin's answer</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2613</link><description>&lt;p&gt;SubProcessRunner.exec(object, param) throws an error (null pointer ex) if it is run from ManagedBean.
If i run it from BussinessProcess it is OK.&lt;/p&gt;
&lt;p&gt;Is this 'by design' ?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stelt0</dc:creator><pubDate>Thu, 11 May 2017 08:09:25 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#2613</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/2476</link><description>&lt;p&gt;Calling a Sub-Process from plain Java has become much simpler &lt;strong&gt;since Axon.ivy 6.3.&lt;/strong&gt; 
There is now a nice fluent API to invoke a process and get back the the resulting data. The entry point is here:
&lt;a href="https://developer.axonivy.com/doc/latest/public-api/ch/ivyteam/ivy/process/call/SubProcessCall.html"&gt;ch.ivyteam.ivy.process.call.SubProcessCall&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can find an example in the ConnectivityDemos where a Java REST-Service implementation starts a Process in the engine. 
See &lt;code&gt;ConnectivityDemos&lt;/code&gt; -&amp;gt; &lt;code&gt;com.axonivy.connectivity.rest.provider.ApprovalService.create(String, String, String)&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ITask task = SubProcessCall.withPath("rest/createApproval")
                .withParam("title", title)
                .withParam("description", description)
                .call()
                .get("approvalTask", ITask.class);
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 03 Mar 2017 09:42:11 -0500</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/2476</guid></item><item><title>Comment by Adrian Imfeld on Adrian Imfeld's answer</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#903</link><description>&lt;p&gt;Yes, you can. But it is just one parameter object of class E. This could also be a parameter-list-object, a JSON string or a ivy dataclass. (Be careful about ivy dataclasses, they are not compatible by diffrent ProcessModelVersions PMV.)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Adrian Imfeld</dc:creator><pubDate>Thu, 07 Aug 2014 09:15:02 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#903</guid></item><item><title>Comment by HaraldWeber on Adrian Imfeld's answer</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#899</link><description>&lt;p&gt;But you can't add parameters to the call.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">HaraldWeber</dc:creator><pubDate>Wed, 06 Aug 2014 12:18:31 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java#899</guid></item><item><title>Answer by Adrian Imfeld</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/887</link><description>&lt;p&gt;&lt;strong&gt;Alternative (with System Events)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I do not like the search of the correct process. &lt;br&gt;
To jump from plain Java in a Ivy process, I recommend an alternative way with System Events. &lt;br&gt;&lt;/p&gt;
&lt;p&gt;You have to change your process a little. Add a "event start" element instead the normal "request start" element. Or you can put it also next to the process start.&lt;/p&gt;
&lt;p&gt;Write your one event bean like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class SystemEventSubscriber extends AbstractProcessStartEventBean {...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or you could use the example from &lt;a href="http://blog.xpertivyhacker.ch/search/label/System%20Event"&gt;ivyhacker&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The java code to jump in the process looks nicer:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;IApplication app = Ivy.wf().getApplication();
SystemEvent&amp;lt;E&amp;gt; event = 
  new SystemEvent&amp;lt;E&amp;gt;(SystemEventCategory.THIRD_PARTY, [identifier-string], [object of type E]);
app.sendSystemEvent(event);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Like this, you are able to jump to any start event with an identifier string, and you could hand out a parameter as an object type of your choice. For further information read this entry &lt;a href="http://blog.xpertivyhacker.ch/search/label/System%20Event"&gt;ivyhacker&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(-) Small process changes&lt;/li&gt;
&lt;li&gt;(+) Posibility to jump to any process step (activity)&lt;/li&gt;
&lt;/ul&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Adrian Imfeld</dc:creator><pubDate>Mon, 28 Jul 2014 13:54:56 -0400</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/887</guid></item><item><title>Answer by Daniel Oechslin</title><link>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/181</link><description>&lt;p&gt;&lt;strong&gt;Since Axon.ivy 4.3&lt;/strong&gt; you can start sub processes like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ISubProcessStart object;
if (className != null) {
    object = getSubProcess(className);
    if (object == null) {
        setProcessDataField(context, STATUS_MESSAGE_PROPERTY, StatusMessage.MESSAGE_TYPE_ERROR);
        return in;
    }
    results= SubProcessRunner.exec(object, param);
}



private ISubProcessStart getSubProcess(String className){

    //Create filter.
    SubProcessSearchFilter filter = SubProcessSearchFilter.create()
            .setProcessPathPattern(className) 
            .toFilter();

    //Result list of processes. picking first only.

    List&amp;lt;ISubProcessStart&amp;gt; foundSubProcesses = SubProcessRunner.findSubProcessStarts(filter);
    if (foundSubProcesses.isEmpty()) {
        return null;
    }
    return foundSubProcesses.get(0);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You need to handle the exceptions within the subprocesses. You can't handle it to the parent class.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Daniel Oechslin</dc:creator><pubDate>Fri, 06 Dec 2013 14:41:50 -0500</pubDate><guid>https://answers.axonivy.com/questions/179/start-a-process-in-plain-java/181</guid></item></channel></rss>