I have create a test function but is not present in Groovy Script user-defined List :
package com.company.script
public class MesScripts {
public static String test() {
return "test"
}
}
Can you help me ?
Thanks
I have create a test function but is not present in Groovy Script user-defined List :
package com.company.script
public class MesScripts {
public static String test() {
return "test"
}
}
Can you help me ?
Thanks
[French version below]
Sounds like you have already a class in a groovy file. Once checked that this class is visible in your project tree, I have two solutions for you. You can keep your current code and manually import your class in the expression Groovy script editor -> see 2). Or you can, as expected in the question name of this topic, make it appears in the "user_defined function" panel -> see 1).
These solutions work for Bonita Studio 7.8 under Windows 7.
Two possible ways : choose one of them.
Right click on "Groovy scripts" in the work tree : create your class (ie : MesScripts) but leave the package name empty. Once created, your class appeared in the "(default package)". In this package, static methods of your class normally appear in the "User defined" panel.
Click on the crayon icon somewhere in the studio to edit an expression (in a operation for instance, or when step selected : General > Portal > displayDescription). Check the "User defined" on right side of th pop-up window.
If your function is not visible, you may have to restart Bonita Studio (I didn't find another way to update the list of available scripts).
You should see your function in the user-defined scripts.
So if you simply write
return MesScripts.test()
and click evaluate, you should have a pop-up windows where your message "test" appears.
Done.
Your function can still be accessed from script expression edition. You simply have to manually import the package.
For this write
import com.company.script.MesScripts return MesScripts.test()
And then the script should work during your process.
Beware : with this method, the button "Evaluate" under the script edition won't work (a multiple compilation exception is thrown). But don't worry, it works during the process when you are using the Bonita Portal.
Done.
I hope it would help. It is up to you to use the solution which fits your needs. Personally I prefer the second solution. Indeed, it allows you to set a personnalized package name, which is for me a good practice.
Il semble que vous ayez déjà une classe dans un fichier Groovy. Après avoir vérifié que votre classse apparaissaît bien dans l'arborescence de votre projet, j'ai deux solutions différentes pour vous. Vous pouvez garder votre script actuel et l'importer manuellement dans le panneau d'édition d'expression Groovy -> voir 2). Ou alors, comme attendu d'après la formulation de la question, faire apparaître votre fonction dans le panneau "User-defined" -> voir 1).
Ces deux solutions fonctionnent pour Bonita Studio 7.8 avec Windows 7.
Cliquez droit sur l'item "Groovy Scripts" dans l'arborescence de votre projet : créez votre classe normalement (nom : MesScripts) mais laissez le nom de package vide. Une fois créé, votre classe apparaît dans le package par défaut (default-package). Une fois dans ce package, les méthodes statiques de vos classes doivent apparaître dans le panneau "user-defined".
Si votre fonction n'apparaît pas dans la liste "user defined", vous devez sans doute redémarrer Bonita Studio (Je n'ai pas trouvé de façon plus rapide de recharger les scripts disponibles).
Vous devez maintenant voir apparaître votre fonction dans la liste des scripts.
Donc si vous écrivez simplement :
return MesScripts.test()
et cliquez sur le bouton "Evaluate", vous devez voir apparaître une pop-up avec "test" marqué à l'intérieur, comme attendu.
Cette fois-ci il faut spécifier le package avant d'utiliser la méthode :
import com.company.script.MesScripts return MesScripts.test()
Le script doit fonctionner pendant l'exécution d'un processus.
Attention : cette fois-ci, le bouton "Evaluate" ne fonctionne pas (exception levée par Groovy).
J'espère vous avoir apporté une aide suffisante, il ne vous reste qu'à utiliser la solution qui vous convient le plus. Personnellement, je préfère la seconde : je pense que pouvoir spécifier le nom d'un package est une bonne pratique.
This solution is ok when calling the script from a process.
But now, we've got an error when calling this script in a subprocess :
2019-03-06 11:21:35.965 +0100 GRAVE: org.bonitasoft.engine.execution.work.InSessionBonitaWork THREAD_ID=128 | HOSTNAME=not11873 | TENANT_ID=1 | The work [ExecuteFlowNodeWork: flowNodeInstanceId: 100297] failed. The failure will be handled. 2019-03-06 11:21:35.966 +0100 GRAVE: org.bonitasoft.engine.execution.work.InSessionBonitaWork THREAD_ID=128 | HOSTNAME=not11873 | TENANT_ID=1 | org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityStateExecutionException : "PROCESS_DEFINITION_ID=5017854892370112667 | PROCESS_NAME=Préparation Consultation | PROCESS_VERSION=1.0 | PROCESS_INSTANCE_ID=5029 | ROOT_PROCESS_INSTANCE_ID=5027 | FLOW_NODE_DEFINITION_ID=6285408241647357089 | FLOW_NODE_INSTANCE_ID=100297 | FLOW_NODE_NAME=DA26 - Envoi mail SCP | org.bonitasoft.engine.core.process.instance.api.exceptions.SProcessInstanceCreationException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression agentDOPSCP() with content = <return MesScripts.ListeMailAgentsDirection(sesamAchat.directionLibelle, "Agent SCP", apiAccessorSesam)> depends on MesScripts is neither defined in the script nor in dependencies." org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityStateExecutionException: PROCESS_DEFINITION_ID=5017854892370112667 | PROCESS_NAME=Préparation Consultation | PROCESS_VERSION=1.0 | PROCESS_INSTANCE_ID=5029 | ROOT_PROCESS_INSTANCE_ID=5027 | FLOW_NODE_DEFINITION_ID=6285408241647357089 | FLOW_NODE_INSTANCE_ID=100297 | FLOW_NODE_NAME=DA26 - Envoi mail SCP | org.bonitasoft.engine.core.process.instance.api.exceptions.SProcessInstanceCreationException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression agentDOPSCP() with content = <return MesScripts.ListeMailAgentsDirection(sesamAchat.directionLibelle, "Agent SCP", apiAccessorSesam)> depends on MesScripts is neither defined in the script nor in dependencies. at org.bonitasoft.engine.execution.StateBehaviors.handleCallActivity(StateBehaviors.java:418) at org.bonitasoft.engine.execution.state.InitializingActivityWithBoundaryEventsStateImpl.afterConnectors(InitializingActivityWithBoundaryEventsStateImpl.java:98) at org.bonitasoft.engine.execution.state.OnEnterOrOnFinishConnectorState.execute(OnEnterOrOnFinishConnectorState.java:65) at org.bonitasoft.engine.execution.state.OnEnterOrOnFinishConnectorState.execute(OnEnterOrOnFinishConnectorState.java:1) at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.executeState(FlowNodeExecutorImpl.java:133) at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.updateState(FlowNodeExecutorImpl.java:184) at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.stepForward(FlowNodeExecutorImpl.java:168) at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.executeFlowNode(FlowNodeExecutorImpl.java:348) at org.bonitasoft.engine.execution.work.ExecuteFlowNodeWork.work(ExecuteFlowNodeWork.java:86) at org.bonitasoft.engine.execution.work.TxBonitaWork.lambda$0(TxBonitaWork.java:42) at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:274) at org.bonitasoft.engine.execution.work.TxBonitaWork.work(TxBonitaWork.java:42) at org.bonitasoft.engine.execution.work.LockProcessInstanceWork.work(LockProcessInstanceWork.java:73) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:41) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:41) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:41) at org.bonitasoft.engine.execution.work.InSessionBonitaWork.work(InSessionBonitaWork.java:59) at org.bonitasoft.engine.work.BonitaThreadPoolExecutor.lambda$submit$1(BonitaThreadPoolExecutor.java:98) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.bonitasoft.engine.core.process.instance.api.exceptions.SProcessInstanceCreationException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression agentDOPSCP() with content = <return MesScripts.ListeMailAgentsDirection(sesamAchat.directionLibelle, "Agent SCP", apiAccessorSesam)> depends on MesScripts is neither defined in the script nor in dependencies. at org.bonitasoft.engine.execution.ProcessExecutorImpl.start(ProcessExecutorImpl.java:838) at com.bonitasoft.engine.execution.ProcessExecutorExt.startSuper(ProcessExecutorExt.java:192) at com.bonitasoft.engine.execution.ProcessExecutorExt.start(ProcessExecutorExt.java:162) at org.bonitasoft.engine.execution.ProcessExecutorImpl.start(ProcessExecutorImpl.java:793) at org.bonitasoft.engine.execution.StateBehaviors.instantiateProcess(StateBehaviors.java:446) at org.bonitasoft.engine.execution.StateBehaviors.handleCallActivity(StateBehaviors.java:407) ... 20 more Caused by: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression agentDOPSCP() with content = <return MesScripts.ListeMailAgentsDirection(sesamAchat.directionLibelle, "Agent SCP", apiAccessorSesam)> depends on MesScripts is neither defined in the script nor in dependencies. at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:144) at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:91) at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:213) at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:120) at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:83) at org.bonitasoft.engine.bpm.model.impl.BPMInstancesCreator.evaluateExpression(BPMInstancesCreator.java:600) at org.bonitasoft.engine.bpm.model.impl.BPMInstancesCreator.createDataInstance(BPMInstancesCreator.java:594) at org.bonitasoft.engine.bpm.model.impl.BPMInstancesCreator.createDataInstances(BPMInstancesCreator.java:568) at org.bonitasoft.engine.execution.ProcessExecutorImpl.initialize(ProcessExecutorImpl.java:384) at org.bonitasoft.engine.execution.ProcessExecutorImpl.start(ProcessExecutorImpl.java:823) ... 25 more Caused by: groovy.lang.MissingPropertyException: No such property: MesScripts for class: BScript704 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) at BScript704.run(BScript704.groovy:1) at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:141) ... 34 more
Have you got an explanation ?
Thanks.
Thanks, the return MesScripts.test() is working in my groovy script.
But my function test() is always not present in my user defined list. I try to restart my studio but the problem is always present.
Which solution have you implemented ? If you have chosen the second solution, by manually importing your function using
import com.company.script.MesScripts return MesScripts.test()
your function doesn't appear in the user defined list. That's the way Bonita works. If you prefer to have your own function become visible in the "user defined function" list, please make your groovy class again and leave the package name field empty at the creation (the first solution in my answer).
If you choose the first solution here is an example of the content of the Groovy file. Note that the file should not include class declaration:
/** * My Groovy function * @return a constant value */ static def String test() { return 'A string' }
If you follow such syntax the Groovy function should be listed under " User defined" category after a Studio restart (it seems that this list is only refresh at Studio startup):
In fact, without class declaration the function is present in User Defined Category
Thanks a lot
Support response :
Ok, the problem was in dependencies :
-a- open diagram
-b- click on pool
-c- click on params (configuration)
-d- click on java dependencies
=> checked the library scripts