create business object when taking a task bonita

1
0
-1

Hello,

I would like to create an object in the database when the user takes a task instead of doing it in the operation(when the user submits the form).

how could this be done?

i tried doing it in a groovy script at the connectors in level as following :

Plan logic :

- if entry exists, return the id,

- if doesn't exist, create it and return the id

Code:

Entry entry = null;
List list = entryDAO.findByDocumentId(document.persistenceId);
if(list.size() > 0){
    entry = list.get(0);
} else {
    entry = new Entry();
    entry.setCreationDate(OffsetDateTime.now());
}
return entry;

but it returns an error saying :

27-Jul-2020 15:09:30.102 SEVERE [ConnectorExecutor-31] org.bonitasoft.engine.log.technical.TechnicalLoggerSLF4JImpl.log THREAD_ID=799 | HOSTNAME=mike-hp-envy-notebook | TENANT_ID=1 | The work [ExecuteConnectorOfActivity: flowNodeInstanceId = 80067, connectorDefinitionName = createEntry] failed. The failure will be handled.
27-Jul-2020 15:09:30.107 SEVERE [ConnectorExecutor-31] org.bonitasoft.engine.log.technical.TechnicalLoggerSLF4JImpl.log THREAD_ID=799 | HOSTNAME=mike-hp-envy-notebook | TENANT_ID=1 | org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException : "org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException: java.lang.IllegalStateException: org.bonitasoft.engine.transaction.STransactionNotFoundException: No active transaction."
org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException: org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException: java.lang.IllegalStateException: org.bonitasoft.engine.transaction.STransactionNotFoundException: No active transaction.
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.lambda$execute$0(ConnectorExecutorImpl.java:159)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException: java.lang.IllegalStateException: org.bonitasoft.engine.transaction.STransactionNotFoundException: No active transaction.
at com.centralInspection.registry.server.SejelEntryDAOImpl.findBySejelDocumentAndPrefix(SejelEntryDAOImpl.java:140)
at com.centralInspection.registry.SejelEntryDAO$findBySejelDocumentAndPrefix.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at Script1.run(Script1.groovy:15)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:612)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:583)
at org.bonitasoft.connectors.scripting.GroovyScriptConnector.executeBusinessLogic(GroovyScriptConnector.java:48)
at org.bonitasoft.engine.connector.AbstractConnector.execute(AbstractConnector.java:77)
at org.bonitasoft.engine.core.connector.impl.SConnectorAdapter.execute(SConnectorAdapter.java:74)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:258)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:217)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.lambda$wrapForStats$1(ConnectorExecutorImpl.java:169)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.lambda$execute$0(ConnectorExecutorImpl.java:156)
... 4 more
Caused by: java.lang.IllegalStateException: org.bonitasoft.engine.transaction.STransactionNotFoundException: No active transaction.
at org.bonitasoft.engine.business.data.impl.JPABusinessDataRepositoryImpl.getEntityManager(JPABusinessDataRepositoryImpl.java:182)
at org.bonitasoft.engine.business.data.impl.JPABusinessDataRepositoryImpl.findByNamedQuery(JPABusinessDataRepositoryImpl.java:308)
at com.centralInspection.registry.server.SejelEntryDAOImpl.findBySejelDocumentAndPrefix(SejelEntryDAOImpl.java:138)
... 19 more
Caused by: org.bonitasoft.engine.transaction.STransactionNotFoundException: No active transaction.
at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.registerBonitaSynchronization(JTATransactionServiceImpl.java:261)
at org.bonitasoft.engine.business.data.impl.JPABusinessDataRepositoryImpl.getEntityManager(JPABusinessDataRepositoryImpl.java:180)
... 21 more

No answers yet.
Notifications