<?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>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>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>