So my current approach is to just handle the error which is thrown when creating a duplicate user.
I used try-catch but it’s not handling in a script of type javascript.
Code I used is:
try{
execution.getProcessEngine().getIdentityService().saveUser(person);
}
catch(e){
throw new org.camunda.bpm.engine.delegate.BpmnError(“jdbcUpdateException”);
}
Hi @teja_polisetty
I created something like this for an example on how to create users and tenets. You can find the full code snippet here. The important stuff looks like this:
final boolean alreadyCreated = this.doesUserAlreadyExist(user.getEmail(), execution);
if (alreadyCreated) {
throw new BpmnError("AlreadyExists");
}
And the method being used there looks like this, instead of email you can use some other identifier i guess.
private boolean doesUserAlreadyExist(final String email, final DelegateExecution execution) {
final User user = (User)execution.getProcessEngineServices().getIdentityService().createUserQuery().userEmail(email).singleResult();
return user != null;
}
Big thanks @Niall
I want to ask one more silly question,
In java we are importing with this statement: import org.camunda.bpm.engine.identity.User;,
How can I import the same in service task script of type javascript in the BPMN.