12-22-2016 11:52 AM
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 ?
01-05-2017 12:21 PM
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
12-22-2016 12:42 PM
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
12-22-2016 01:13 PM
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
12-22-2016 01:23 PM
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; out.println('Start - Init'); List<User> users = userService.getAllUsers(0,999,tenantId); execution.setVariable('assigneeList', idList); out.println('End - Init'); |
Regards,
Greg
01-05-2017 12:21 PM
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
10-11-2017 02:58 PM
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
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.