Bonitasoft Groovy Script

Bonitasoft Groovy Scripts to Get Users Data


Using below Groovy Script code you will get the complete information of a particular user in Bonitasoftt

To get Manager Email address in Bonitasoft:

${import org.ow2.bonita.facade.IdentityAPI;
import org.ow2.bonita.facade.identity.User;
IdentityAPI api = apiAccessor.getIdentityAPI();
User user = api.findUserByUserName(processInstance.getStartedBy());
User manager1 = api.getUserByUUID(user.getManagerUUID());
return manager1.email;
}

To get Professional Email of a user :

${import org.ow2.bonita.facade.IdentityAPI;
import org.ow2.bonita.facade.identity.User;
IdentityAPI api = apiAccessor.getIdentityAPI();
User user = api.findUserByUserName(processInstance.getStartedBy());
User manager1 = api.getUserByUUID(user.getManagerUUID());
User supermanager = api.getUserByUUID(manager1.getManagerUUID());
return supermanager.getProfessionalContactInfo().getEmail();
}

To get user Department :

${import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;
import org.ow2.bonita.facade.APIAccessor;
final APIAccessor accessor = new StandardAPIAccessorImpl();
def theUser = accessor.getIdentityAPI().findUserByUserName(loggedUser);
if(theUser!=null){
def title=theUser.getTitle();

if(title!=null){
return title ;
}
}
}

To get User Email Address:

${import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;
import org.ow2.bonita.facade.APIAccessor;
final APIAccessor accessor = new StandardAPIAccessorImpl();
def theUser = accessor.getIdentityAPI().findUserByUserName(loggedUser);
if(theUser!=null){
def contact=theUser.getProfessionalContactInfo();
if (contact!=null){
return contact.getEmail()
}
}}

To get User Firstname and LastName in Bonitasoft:

${import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;
import org.ow2.bonita.facade.APIAccessor;
final APIAccessor accessor = new StandardAPIAccessorImpl();
def theUser = accessor.getIdentityAPI().findUserByUserName(loggedUser);
if(theUser!=null){
def firstname=theUser.getFirstName();
def lastname=theUser.getLastName();
if(firstname==null||lastname==null||firstname.equals("")||lastname.equals("")){
return loggedUser;
}else {
return firstname + " " + lastname;
}
}
return loggedUser;}

To get Users Manager Name:

${import org.ow2.bonita.facade.IdentityAPI;
import org.ow2.bonita.facade.identity.User;
IdentityAPI api = apiAccessor.getIdentityAPI();
User user = api.findUserByUserName(processInstance.getStartedBy());
User manager1 = api.getUserByUUID(user.getManagerUUID());

return manager1.username;
}

To get Designation:

${import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;
import org.ow2.bonita.facade.APIAccessor;
final APIAccessor accessor = new StandardAPIAccessorImpl();
def theUser = accessor.getIdentityAPI().findUserByUserName(loggedUser);
if(theUser!=null){
def jobtitle=theUser.getJobTitle();

if(jobtitle!=null){
return jobtitle;
}
}
}

To get phone number :

${import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;
import org.ow2.bonita.facade.APIAccessor;
final APIAccessor accessor = new StandardAPIAccessorImpl();
def theUser = accessor.getIdentityAPI().findUserByUserName(loggedUser);
if(theUser!=null){
def phonenumber=theUser.getProfessionalContactInfo();
if (phonenumber!=null){
return phonenumber.getPhoneNumber()
}
}}

To get Mobile Number in Bonitasoft use below code :

${import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;
import org.ow2.bonita.facade.APIAccessor;
final APIAccessor accessor = new StandardAPIAccessorImpl();
def theUser = accessor.getIdentityAPI().findUserByUserName(loggedUser);
if(theUser!=null){
def mobilenumber=theUser.getProfessionalContactInfo();
if (mobilenumber!=null){
return mobilenumber.getMobileNumber()
}
}}

To get Department Code in Bonitasoft use below code :

${import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;
import org.ow2.bonita.facade.APIAccessor;
final APIAccessor accessor = new StandardAPIAccessorImpl();
def theUser = accessor.getIdentityAPI().findUserByUserName(loggedUser);
if(theUser!=null){
def faxnumber=theUser.getPersonalContactInfo();
if (faxnumber!=null){
return faxnumber.getFaxNumber()
}
}}