<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Get Taskruntime</title><link>https://answers.axonivy.com/questions/2118/get-taskruntime</link><description>&lt;p&gt;Hello,
I need to know the runtime of a task in a running process.
I found a method to get a taskruntime in a process but it is not that easy I expected. Now my question, is there a less complicated way to get the runtime of a task?
My way:
It is written in the call tab of a user dialog in between 2 task symbols&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ivy.log.info("Startzeit Task "+in.startTaskTime);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is written in a script step behind the task whilst in.nummer the case nubmer is to get the last entry&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;TaskQuery  tazk = TaskQuery.create().where().name().isEqual("Task1Name");
Recordset taskZeit = ivy.wf.getTaskQueryExecutor().getRecordset(tazk.groupBy().endTimestamp());
ivy.log.info("TaskEndeZeit2: "+taskZeit.getColumn("ENDTIMESTAMP").get(in.nummer));
&lt;/code&gt;&lt;/pre&gt;</description><atom:link href="https://answers.axonivy.com/questions/2118/get-taskruntime" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 21 Oct 2016 10:28:54 -0400</lastBuildDate><item><title>Comment by Gabriele on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/2118/get-taskruntime#2127</link><description>&lt;p&gt;Thank's a lot, now it works, I only had to cast the return value from getEndTimestamp().getTime() and getStartTimestamp().getTime to a number.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Gabriele</dc:creator><pubDate>Fri, 21 Oct 2016 10:28:54 -0400</pubDate><guid>https://answers.axonivy.com/questions/2118/get-taskruntime#2127</guid></item><item><title>Comment by Reguel Wermelinger on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/2118/get-taskruntime#2123</link><description>&lt;p&gt;Then I guess that you are using the code in ivyScript. I've adjusted the sample with a proper ivyScript casting: &lt;code&gt;as ITask&lt;/code&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 20 Oct 2016 14:58:40 -0400</pubDate><guid>https://answers.axonivy.com/questions/2118/get-taskruntime#2123</guid></item><item><title>Comment by Gabriele on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/2118/get-taskruntime#2122</link><description>&lt;p&gt;Thank's for your help, but the method "getFirstResult(query)" returns an object and I can't cast it to a type ITask.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Gabriele</dc:creator><pubDate>Thu, 20 Oct 2016 14:51:24 -0400</pubDate><guid>https://answers.axonivy.com/questions/2118/get-taskruntime#2122</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/2118/get-taskruntime/2119</link><description>&lt;pre&gt;&lt;code&gt;TaskQuery query = TaskQuery.create().where().name().isEqual("Task1Name").groupBy().endTimestamp();
ITask task = ivy.wf.getTaskQueryExecutor().getFirstResult(query) as ITask;
long taskRuntimeMillis = task.getEndTimestamp().getTime() - task.getStartTimestamp().getTime();
ivy.log.info("task runtime: "+taskRuntimeMillis);
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 20 Oct 2016 11:25:09 -0400</pubDate><guid>https://answers.axonivy.com/questions/2118/get-taskruntime/2119</guid></item></channel></rss>