cancel
Showing results for 
Search instead for 
Did you mean: 

How to get user firstname and lastname in a generated document

r_kister
Champ on-the-rise
Champ on-the-rise

Hello,

I work on a process that generate a document in enterprise version of Activiti.

In my process, i select a people in a form and i would like to have his firstname and his lastname in the generated document.

If i put this in the document template

<<[vacataire]>>

where vacataire is the form ID, i get his user ID.

Is there a way to get his firstname and his lastname ?

1 ACCEPTED ANSWER

r_kister
Champ on-the-rise
Champ on-the-rise

Hi Greg,

Thank you for your response.

To get firstName, lastName and Email of a people, i use "userInfoBean" in a JavaScript Script Task :

var vacataireID = execution.getVariable("vacataire");
var vacataireNom = userInfoBean.getLastName(vacataireID, execution);
var vacatairePrenom = userInfoBean.getFirstName(vacataireID, execution);
var vacataireEmail = userInfoBean.getEmail(vacataireID, execution);‍‍‍‍‍


execution.setVariable("vacataireNom", vacataireNom);
execution.setVariable("vacatairePrenom", vacatairePrenom);
execution.setVariable("vacataireEmail", vacataireEmail);

Regards,

Raphael

View answer in original post

5 REPLIES 5

gdharley
Elite Collaborator
Elite Collaborator

Hi,

As you found out, the Person picker populates a user id (long) which isn't much help.

However, you can retrieve the User object using the userService bean from within a script task or listener:

com.activiti.domain.idm.User user = userService.findActiveUser(userId);

Once you have this simply call getFirstName() and getLastName() on the returned User object.

Unfortunately the userService is not well documented yet.

Hope this helps,

Greg

r_kister
Champ on-the-rise
Champ on-the-rise

Hi Greg,

Thank you for your response.

How can i get the userService in a listener ?

Can you give me an example code of a listener or script task (javascript) with use of userService.

Raphael

gdharley
Elite Collaborator
Elite Collaborator

Raphael,

userService is exposed as a bean in Activiti Enterprise, therefore you simply access it by its name.
The following simply groovy script task code retrieves all users and populates their ID's into a process variable :

Script Task

import com.activiti.domain.idm.User;
import com.activiti.security.SecurityUtils;

out.println('Start - Init');
ArrayList idList = new ArrayList();
Long tenantId = SecurityUtils.getCurrentUserObject().getTenantId();

List<User> users = userService.getAllUsers(0,999,tenantId);
for (User u : users) {
idList.add(u.getId());
}

execution.setVariable('assigneeList', idList);

out.println('End - Init');

Regards,

Greg

r_kister
Champ on-the-rise
Champ on-the-rise

Hi Greg,

Thank you for your response.

To get firstName, lastName and Email of a people, i use "userInfoBean" in a JavaScript Script Task :

var vacataireID = execution.getVariable("vacataire");
var vacataireNom = userInfoBean.getLastName(vacataireID, execution);
var vacatairePrenom = userInfoBean.getFirstName(vacataireID, execution);
var vacataireEmail = userInfoBean.getEmail(vacataireID, execution);‍‍‍‍‍


execution.setVariable("vacataireNom", vacataireNom);
execution.setVariable("vacatairePrenom", vacatairePrenom);
execution.setVariable("vacataireEmail", vacataireEmail);

Regards,

Raphael

Hi, I have a similar issue.. I am calling my bean

import com.activiti.domain.idm.User;
import com.activiti.service.api.UserService;

@Autowired

static UserService userService;

public static String getProjectID(DelegateExecution execution) {

Long userid = SecurityUtils.getCurrentUserId();   <--------- NOTHING is retured....

Got userID through

List<IdentityLink> identityLink = processEngine.getRuntimeService().getIdentityLinksForProcessInstance(processID);

User user = userService.findUser(userid);  <------ NOTHING AGAIN

}