I tried to create a user in bonita portal using a script task.
use the following code and failed without success.
// First of all, let's log in on the engine: org.bonitasoft.engine.api.APIClient apiClient = new APIClient() apiClient.login("install", "install") // create new user, with username john and password bpm IdentityAPI identityAPI = apiClient.getIdentityAPI() final User user = identityAPI.createUser("john", "bpm") System.out.println("New user created: " + user)
Is it possible to create bonita user using script task? If possible what am I got wrong here?
When you are executing a script in a process operation or a connector, you are already executing code server side as a technical use, so should not try to call the Login service.
This script should just work fine:
// Use the apiAccessor from a Groovy script to retrieve the Bonita apis
def identityAPI = apiAccessor.getIdentityAPI()
// create complex user
UserCreator creator = new UserCreator("john", "bpm")
creator.setFirstName("Johnny").setLastName("B. Good")
ContactDataCreator proContactDataCreator = new ContactDataCreator().setAddress("32 rueGustave Eiffel").setCity("Grenoble").setPhoneNumber("555 14 12 541")
creator.setProfessionalContactData(proContactDataCreator)
final User user2 = identityAPI.createUser(creator)
// Let's set the connection settings to use HTTP on the already running Bonita runtime:
Map<String, String> settings = new HashMap<String, String>();
settings.put("server.url", "http://localhost:3381");
settings.put("application.name", "bonita");
APITypeManager.setAPITypeAndParams(ApiAccessType.LOCAL, settings);
APIClient apiClient = new APIClient()
// create new user, with username john and password bpm
IdentityAPI identityAPI = apiClient.getIdentityAPI()
// create complex user
UserCreator creator = new UserCreator("john", "bpm")
creator.setFirstName("Johnny").setLastName("B. Good")
ContactDataCreator proContactDataCreator = new ContactDataCreator().setAddress("32 rueGustave Eiffel").setCity("Grenoble").setPhoneNumber("555 14 12 541")
creator.setProfessionalContactData(proContactDataCreator)
final User user2 = identityAPI.createUser(creator)
this is the exception
Caused by: org.bonitasoft.engine.core.operation.exception.SOperationExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Groovy script throws an exception of type class org.bonitasoft.engine.platform.LoginException with message = org.bonitasoft.engine.transaction.STransactionCreationException: We do not support nested calls to the transaction service. Current state is: 0.
Expression : SExpressionImpl [name=createNewUserScript(), content=import org.bonitasoft.engine.api.APIClient
Bonitasoft empowers development teams with Bonita, the open-source and extensible platform to solve the most demanding process automation use cases. The Bonita platform accelerates delivery of complex applications with clear separation between capabilities for visual programming and for coding. Bonita integrates with existing solutions, orchestrates heterogeneous systems, and provides deep visibility into processes across the organization.