I cant update user custom info by groovy script

1
0
-1

Hi

I need to update a user custom info value using a groovy script after a task did complete.

I have a script task, befor end process and after the main task. Inside a script task there is a Script connector with this code inside:

import org.bonitasoft.engine.api.CustomUserInfoAPI
import org.bonitasoft.engine.identity.CustomUserInfoValue

CustomUserInfoAPI customInfo;

return customInfo.setCustomUserInfoValue(106, 301, "78");

Where: 106 is the Definition Id of the custom info. 301 is the User Id, and 78 is the value to update.

So, when a run the task this is the error log:

021-02-02 11:24:14.681 -0300 INFORMACIÓN: org.bonitasoft.engine.api.impl.ProcessStarter THREAD_ID=109 | HOSTNAME=CRISTIAN | TENANT_ID=1 | The user has started the process instance <75004> of process
in version <1.0> and id <4786766726863350203>
2021-02-02 11:25:56.550 -0300 INFORMACIÓN: org.bonitasoft.engine.api.impl.ProcessAPIImpl THREAD_ID=118 | HOSTNAME=CRISTIAN | TENANT_ID=1 | The user has executed the task [name = , display name = , id = <1460024>, parent process instance = <75004>, root process instance = <75004>, process definition = <4786766726863350203>] with task inputs: {diasPendientes=22}
2021-02-02 11:25:57.429 -0300 GRAVE: org.bonitasoft.engine.execution.work.InSessionBonitaWork THREAD_ID=184 | HOSTNAME=CRISTIAN | TENANT_ID=1 | The work [ExecuteConnectorOfActivity: flowNodeInstanceId = 1460024, connectorDefinitionName = setDiasPendientes] failed. The failure will be handled.
2021-02-02 11:25:57.437 -0300 GRAVE: org.bonitasoft.engine.execution.work.InSessionBonitaWork THREAD_ID=184 | HOSTNAME=CRISTIAN | TENANT_ID=1 | org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException : "java.lang.NullPointerException: Cannot invoke method setCustomUserInfoValue() on null object"
org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException: java.lang.NullPointerException: Cannot invoke method setCustomUserInfoValue() on null object
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.lambda$execute$0(ConnectorExecutorImpl.java:155)
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: java.lang.NullPointerException: Cannot invoke method setCustomUserInfoValue() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:34)
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:144)
at Script1.run(Script1.groovy:13)
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:73)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:253)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:212)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.lambda$wrapForStats$1(ConnectorExecutorImpl.java:164)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.lambda$execute$0(ConnectorExecutorImpl.java:152)
... 4 more

Thanks for the help!

Cristian

2 answers

1
0
-1

Hi Cristian,
you should always retrieve the definitionId using a search by definition name. Depending on the environment where the process is executed the id may differ.
Here is a snippet of how to achieve this:

def definition = apiAccessor.identityAPI
        .getCustomUserInfoDefinitions(0, 99)
        .find{ it.name == 'My Custom User Info Definition Name'}
apiAccessor.identityAPI.setCustomUserInfoValue(definition.id, userId, value)

HTH
Romain

1
0
-1

Hola Cristian,

How is your value initialized? From what I understand from the error, your object CustomUserInfo is Null, which is not possible. To be able to call the method and update the value, your object has to be initialized and instantiated first.

Comments

Submitted by remoncristian on Fri, 02/19/2021 - 12:12

Ok. Thanks.

I will read some API documentation about how initialized it.

Notifications